Filter löschen
Filter löschen

MATLAB cannot call or index into a temporary array in for loop

1 Ansicht (letzte 30 Tage)
hello_world
hello_world am 17 Mai 2016
Kommentiert: Walter Roberson am 17 Jul. 2018
Hello Friends,
Here is my code:
M = {'a', 'b', 'c'};
for i = length(M)
M(i) = M(i)(M(i)~=0);
end
In other words, I am trying to get for each vector 'a', 'b', and 'c' the following in for loop:
a = a(a~=0);
b = b(b~=0);
c = c(c~=0);
I get the following error: "cannot call or index into a temporary array"
I will appreciate any advice.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 17 Mai 2016
I don't know what you want, your example is not appropriate, comparing letters with 0!
A=[1 2 0 5 0 7]
B=A(A~=0)
  1 Kommentar
hello_world
hello_world am 17 Mai 2016
Bearbeitet: hello_world am 17 Mai 2016
I have a cell array, and I want to remove 0 entries from M. I want to do it for each 'a', 'b' and 'c' in for loop. In other words, it will be
a = a(a~=0);
b = b(b~=0);
c = c(c~=0);

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 18 Mai 2016

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by