0
votes

I have a stucture of contourdata of an image in MATLAB. Is is as follows:

s = 
1x59 struct array with fields:
    level
    numel
    xdata
    ydata
 %s(k).level contains the contour level height of the k-th line.
% s(k).numel contains the number of points describing the k-th line.
% sk).isopen is True if the k-th contour is open and False if it is closed.
% s(k).xdata contains the x-axis data for the k-th line as a column vector.
% s(k).ydata contains the y-axis data for the k-th line as a column vector 

I must to extract s(k).xdata and s(k).ydata into matrix with variable size. This is the program i have made

for k=1:59;    
    if (k==1);
        i(k)=s(k).numel;  
        [i,2]=size(S{k}(:,:));
        x=s(k).xdata;
        y=s(k).ydata;
        S{k}(:,:)=[x y];       
    elseif (k>1 && k<=59)
        i(k)=s(k).numel;  
        l=i(k-1)+i(k)
        [i,2]=size(S{k}(:,:));
        x=s(k).xdata;
        y=s(k).ydata;
        S{k}(:,:)=[x y]; 
        S(:,:)=[S{k-1}(:,:);S{k}(:,:)];  
    end   
end

??? Error: An array for multiple LHS assignment cannot contain numeric value

Can anyone help me? Thank you so much in advance!

1

1 Answers

2
votes

The following should replace all of your code:

S = cell2mat(arrayfun(@(x)[x.xdata x.ydata],s','UniformOutput',false))

This makes a cell array with elements your code calls [x y] and combines it into one array S.

Note that calling size in your code doesn't set the size of S{k}, it just tries to set i to the size.