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

6 Ansichten (letzte 30 Tage)
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 Kommentar
Jan
Jan am 27 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 27 Mär. 2017
Bearbeitet: Jan am 27 Mär. 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 Kommentar
Franklyn Dunbar
Franklyn Dunbar am 27 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by