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

8 ビュー (過去 30 日間)
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 件のコメント
Jan
Jan 2017 年 3 月 27 日
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.

サインインしてコメントする。

採用された回答

Jan
Jan 2017 年 3 月 27 日
編集済み: Jan 2017 年 3 月 27 日
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 件のコメント
Franklyn Dunbar
Franklyn Dunbar 2017 年 3 月 27 日
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);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by