MATLAB: Using meshgrid from cell array error – “Undefined function full for input arguments of type cell”

forloopmeshgridplot

I am getting an error when trying to use the meshgrid function after creating an array from a structure using a for loop.
if true
%function (A,B) = 'Plot Output'
% This function takes input from the numbers of observation points for the % TABOO input and corresponds the observation point with the calculations % on the output files 'rate.his' and 'disp.his'
B = load ('obspoints.txt'); num_obs = length(B);
%num_obs = 11;
fid = fopen('rate.his') ;
if fid == -1
disp ('File open not working')
else
disp('File open worked!')
S = textscan(fid,'%s','delimiter','\n') ; %scans text
S = S{1} ;
%get locations where # not present
qwe= strfind(S, '#'); %locates string '#'
qwe = find((cellfun('isempty',qwe)));
%create new array sans '#'
qwer = cell2mat(cellfun(@str2num,S(qwe),'un',0)) ;
qwerl = length(qwer);
closeresult = fclose(fid);
if closeresult == 0
disp('File Close worked')
else
disp('File Close failure')
end
end
for n= 1:num_obs - 1
zxa = n + (n-1)*10; %functions which give the column interval on the above
%matrice which correspond to each time stamp on the observation point
zxb = n + (n-1)*10 + 10;
rate(n).long = B(n,2);
rate(n).lat = B(n,1);
rate(n).time = qwer(zxa:zxb,1);
rate(n).dvert = qwer(zxa:zxb,2);
rate(n).dnorth = -1*qwer(zxa:zxb,3);
rate(n).deast = qwer(zxa:zxb,4);
rate(n).dgeoid = qwer(zxa:zxb,5);
rate(n).mass = qwer(zxa:zxb,6);
end
cell = struct2cell(rate);
% After the structure has been created, different outputs can be easibly % accessed, but must be turned back into a cell from the structure, and % a foor loop is used to fill up the arrays so the meshgrid function can be % used
for n= 1:num_obs - 1
long(n) = cell(1,:,n);
lat(n) = cell(2,:,n);
dvert(n)= cell(4,:,n);
end
[X,Y] = meshgrid(long,lat);
% code
end
the error message is:
Undefined function 'full' for input arguments of type 'cell'.
Error in meshgrid (line 56) xrow = full(x(:)).'; % Make sure x is a full row vector.

Best Answer

All we see is the failing code:
[X,Y] = meshgrid(long,lat);
You provide a cell array as inputs and this must fail. But what is the intention? I guess:
long = [cell(1, :, :)]; % Attention: not the builtin cell function
lat = [cell(2, :, :)];
[X,Y] = meshgrid(long,lat);
This is a guess only. Are you sure that the conversion from structs to cells to vectors is useful? What about storing the data in a struct instead of a struct array:
% rate(n).long = B(n,2); ==>
rate.long(n) = B(n,2);
Then you can omit the conversions and run directly:
[X,Y] = meshgrid(rate.long, rate.lat);
Related Question