conversion from double to cell is not possible
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Bhaskar R
2020년 1월 5일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!