conversion to cell from double
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
per isakson
el 18 de Abr. de 2016
Editada: per isakson
el 18 de Abr. de 2016
Replace
sdata(:,3) = Erate;
by
sdata(:,3) = {Erate};
might help. Or better
dbstop if error
and inspect the types of the variable values involved
Respuestas (0)
Ver también
Categorías
Más información sobre Data Types en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!