Move string values to different variables

1 Ansicht (letzte 30 Tage)
Jose Grimaldo
Jose Grimaldo am 1 Apr. 2020
Kommentiert: Walter Roberson am 1 Apr. 2020
I have a string array 6x1 and I want to move the odds index string to variable v1 and the even index string to v2. I want to do it using loops.
A=string array 6x1
[row,col]=size(A)
v1=A(1);
v2=A(2);
for x=1:row-1
v1(x)=A(x+(x+1))
V2(x)=A(x+2)
end
  1 Kommentar
Walter Roberson
Walter Roberson am 1 Apr. 2020
v1(x)=A(x+(x+1))
V2(x)=A(x+2)
when x is 1, then that would be A(3) and A(3) .
when x is 2, then that would be A(5) and A(4)
When x is 3, then that would be A(7) and A(5) but A(7) does not exist

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Characters and Strings 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