Using meshgrid from cell array error - "Undefined function full for input arguments of type cell"

8 views (last 30 days)
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.
  1 Comment
Jan
Jan on 27 Mar 2017
Using "cell" as a name of a variable shadows the builtin function with the same name. This does not cause the problems here, but it is a frequent source of bugs.

Sign in to comment.

Accepted Answer

Jan
Jan on 27 Mar 2017
Edited: Jan on 27 Mar 2017
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);
  1 Comment
Franklyn Dunbar
Franklyn Dunbar on 27 Mar 2017
Thanks for that, changed to
if true
% code
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(1).long(n) = B(n,2);
rate(1).lat(n) = 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
[X,Y] = meshgrid(rate(1).long,rate(1).lat);

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!