conversion from double to cell is not possible
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have just started to learn matlab. I get the folowing error when the below mentioned function is executed.
Error using cell
Conversion to double from cell is not possible.
Error in sparse2matrix (line 2)
num_array(y)=cell(a(1,1),a(1,2));
when this statement is executed separately no such errors occur.
plzz help me .
Thank you in advance.
function x=sparse2matrix(a,b,c,d)
y=cell(a(1,1),a(1,2));
y(:)={b};
y{c(1,1),c(1,2)}={c(1,3)};
y{d(1,1),d(1,2)}={d(1,3)};
x=cell2mat(y);
end
2 commentaires
Réponses (1)
Bhaskar R
le 5 Jan 2020
I don't know what you are trying to do with given code, if I assume by name of the mentioned function name "sparse to matrix conversion", to do this sparse to matrix conversion MATLAB has a command
full
Issues in your code
you have passed variables to function as
sparse2matrix({[2 3], 0, [1 2 3], [2 2 -3]}); % actually it is only one input
This means you are paasing only single variable as cell type to the function, i.e. single varible consist 4 values in it
so if you want to pass variables as defined in function call the function as
sparse2matrix([2 3], 0, [1 2 3], [2 2 -3]); % remove {}, which makes cell array
And one more issue with code is values assigned as cell type so modify as
function x=sparse2matrix(a,b,c,d)
y=cell(a(1,1),a(1,2));
y(:)={b};
y(c(1,1),c(1,2))={c(1,3)}; % {} replaced with ()
y(d(1,1),d(1,2))={d(1,3)}; % {} replaced with ()
x=cell2mat(y);
end
% Note : it's assumption only to get error output
0 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!