Can someone teach me how this code is excecuted?

조회 수: 1 (최근 30일)
Sachin Nath P M
Sachin Nath P M 2020년 6월 27일
편집: Rohith Nomula 2020년 6월 27일
function matrix = sparse2matrix(cellvec)
row = cellvec{1,1}(1,1);
col = cellvec{1,1}(1,2);
[m,n] = size(cellvec);
matrix = ones(row,col) * cellvec{1,2};
for ii = 3:n
row1 = cellvec{1,ii}(1,1);
col1 = cellvec{1,ii}(1,2);
matrix(row1,col1) = cellvec{1,ii}(1,3);
ii = ii +1;
end

답변 (1개)

Rohith Nomula
Rohith Nomula 2020년 6월 27일
편집: Rohith Nomula 2020년 6월 27일
There is no need of i=i+1 in the for loop
function matrix = sparse2matrix(cellvec)
row = cellvec{1,1}(1,1);
col = cellvec{1,1}(1,2);
[m,n] = size(cellvec);
matrix = ones(row,col) * cellvec{1,2};
for i = 3:n
row1 = cellvec{1,i}(1,1);
col1 = cellvec{1,i}(1,2);
matrix(row1,col1) = cellvec{1,i}(1,3);
end
Again I don't know what the question is. But..
execute the code in command window - go to the path of existing file
>> sparse2matrix(c)
Where c is your cell vector

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by