Cell matrix

조회 수: 4 (최근 30일)
john
john 2012년 4월 30일
Hi,
I have matrix of size 6x6. And I have numbers and text in it. How can I write zero "0" only from row 3 to 6 and from column 1 to 4. I have this code:
UserData.matrix=cell(6,6);
for i=3:6
for j=1:4
UserData.matrix{i,j}='0';
end;
end;
But I got error:"??? Error using ==> mupadmex Error in MuPAD command: Invalid index [list];
during evaluation of 'matchNonSingletonLHS'"
Can anybody help my?

채택된 답변

Thomas
Thomas 2012년 4월 30일
I think you need to do..
UserData.matrix(i,j)={'0'}; % notice where we have parenthesis (indexing) and curly braces for the values
E.g.
% define a cell (6x6)
a={'1' '2' '3' 'hi' '5' '6'; '2' '3' '4' '5' '6' 'the';'1' '2' '3' 'hi' '5' 'new';'1' '2' '3' 'hi' '5' 'world';'1' '2' '3' 'hi' '5' 'welcome';'Where' '2' '3' 'hi' '5' '6';}
a(3:6,1:4)={'0'} % no need of loop

추가 답변 (1개)

Jan
Jan 2012년 4월 30일
The posted code and the error message do not match. There is no index "list" in the code. Please read the error message again to find out, which line causes the problem. Using the debugger is recommended also:
dbstop if error
Then Matlab stops as soon as the error occurs and you can inspect the current values.

카테고리

Help CenterFile Exchange에서 Matrix and Vector Construction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by