开发者

how to apply a matlab fit function to every row of matrix

开发者 https://www.devze.com 2023-02-22 08:21 出处:网络
I need to fit with the fourier function every successive row of the matrix avoiding to use for loop. I tried to use a cell array but have no idea how to use it with fit.

I need to fit with the fourier function every successive row of the matrix avoiding to use for loop. I tried to use a cell array but have no idea how to use it with fit. My program is

I=imread('test.tif','tif');  
I=double(I);  
nat=num2cell(I,1);  
wy_I=cellfun(@size,nat, 'UniformOutput', false);  
we_I=cellfun(@(x)1:x(1), wy_I, 'UniformOutput', false);  
wyn=cellfun(@(x,y)fit(x',y,'fourier1'), we_I, nat);   

It gives ??? Error using ==> cellfun cfit type is not currently implemented. probably cell array is not a solution for this problem. How to solve this problem? Thanks

Update

wyn=cellfun(@(x,y)fit(x',y,'fourier1'), we_I, nat, 'UniformOutput',false);  

works without errors but wyn have only empty cells

I test it for one row

j=cell2mat(we_I(1,1))  
开发者_JAVA百科k=cell2mat(nat(1,1))  
z=fit(j',k,'fourier1')  

and z contains good values for model

I do something wrong with syntax in cellfun but have not idea what


The FIT function returns an object of type cfit in this example. The error would appear to suggest that CELLFUN is unable to collect these objects into an array of type cfit to return as an output. I would instead try returning a cell array of cfit objects by adding 'UniformOutput',false to the last line as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消