Azzera filtri
Azzera filtri

Cell matrix

2 visualizzazioni (ultimi 30 giorni)
john
john il 30 Apr 2012
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?

Risposta accettata

Thomas
Thomas il 30 Apr 2012
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

Più risposte (1)

Jan
Jan il 30 Apr 2012
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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by