Putting array indexes into a larger one

1 次查看(过去 30 天)
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

采纳的回答

Deepak Gupta
Deepak Gupta 2020-5-6
编辑:Deepak Gupta 2020-5-6
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 个评论
Deepak Gupta
Deepak Gupta 2020-5-6
编辑:Deepak Gupta 2020-5-6
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by