conversion to cell from double

조회 수: 3 (최근 30일)
Wesley
Wesley 2016년 4월 18일
편집: per isakson 2016년 4월 18일
Hello,
I'm trying to compile data into a matrix or cell array, but I've settled on a cell array in order to index (within the array) the data I'm compiling with it's source (a string that indicates a name).
I've included some code to help. (chandata starts as a ~1000 row by 10 row matrix [double]):
function [] = KsnEro(wname, sname, bname)
%The purpose of this script is to load Ksn files produced by 'geomorphtools'
% and match it to erosion values from Balco, 2013 paper.
%wname = watershed name
%sname = stream name
%bname = Stream designation in Balco Sampling system
%Load stream data
matlab_workdir = strcat('/Volumes/vonDassow/DEM_Analysis/Balco/', wname)
load(strcat(sname, '_chandata'))
n = size(chandata,1);
nameMat = repmat({sname}, n, 1);
ksn_all = chandata(:,8);
ksn_allmat = num2cell(ksn_all);
%Load Erosion Rate Data --> Must already be a Matlab file (table).
load('/Volumes/vonDassow/DEM_Analysis/Balco/Balco_ErosionRates.mat')
Erate = ones(n,1);
E1 = length(BalcoEro);
% % % Erate = num2cell(Erate)
%strmatch bname to BalcoEro, extract row of str match
for i = 1:E1
if strmatch(BalcoEro(i,1), bname) == 1
fprintf('It worked')
BCurrent = BalcoEro(i,2); %BCurrent = value being taken.
BCurrent = cell2mat(BCurrent);
Erate(:,1) = BCurrent
break
else
fprintf('It did not work')
end;
end
%sdata is for only 1 strea, i.e. Alsea1, Alsea2, etc.
sdata = cell(n,3);
sdata(:,1) = nameMat;
sdata(:,2) = ksn_allmat;
sdata(:,3) = Erate;
My error occurs in this last line 'sdata(:,3) = Erate;', below
Conversion to cell from double is not possible.
Error in KsnEro (line 43)
sdata(:,3) = Erate;
  댓글 수: 1
per isakson
per isakson 2016년 4월 18일
편집: per isakson 2016년 4월 18일
Replace
sdata(:,3) = Erate;
by
sdata(:,3) = {Erate};
might help. Or better
dbstop if error
and inspect the types of the variable values involved

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by