Putting array indexes into a larger one

1 Ansicht (letzte 30 Tage)
center
center am 6 Mai 2020
Bearbeitet: Deepak Gupta am 6 Mai 2020
I have 200x1 bitcells, every cell element is made by 3x1 char strings, represents 3 bits like '101' . I am reading this cells as integers, then I attain -1 or 1 value. The problem is when I try to put this -1 and 1s into 600x1 volts array, it puts wrong values, some elements are missed so stays 0. I checked the singlevolts array always true in every iteration but I couldn't put that values in 600x1 array correctly. Any help will appreciated, thank you community. Stay safe!
for m=1:1:200
for n=1:1:3
if (str2num(bitcells{m}(n)) == 0)
singlevolts(n) = -1
else singlevolts(n) = 1
end
end
volts(m*1) = singlevolts(1)
volts(m*2) = singlevolts(2)
volts(m*3) = singlevolts(3)
end

Akzeptierte Antwort

Deepak Gupta
Deepak Gupta am 6 Mai 2020
Bearbeitet: Deepak Gupta am 6 Mai 2020
Hello Mert,
I am not completely sure what you want to do but got some impression so have made some modification in your code.
for m=1:1:200
for n=1:1:3
if (str2num(bitcells{m}(n)) == 0)
singlevolts(n) = -1
else singlevolts(n) = 1
end
end
volts(3*(m-1)+1) = singlevolts(1);
volts(3*(m-1)+2) = singlevolts(2);
volts(3*(m-1)+3) = singlevolts(3);
end
If this doesn't solve your problem, then attach your cell array, with required end result.
Cheers.
  1 Kommentar
Deepak Gupta
Deepak Gupta am 6 Mai 2020
Bearbeitet: Deepak Gupta am 6 Mai 2020
for m=1:200
for n=1:3
if (str2num(bitcells{m}(n)) == 0)
singlevolts= -1
else singlevolts= 1
end
volts(3*(m-1)+n) = singlevolts;
end
end
It can do the same thing.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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