- What is the significance of the information contained in the array?
- Why does it change size every iteration?
- What is the expected data contained in the array?
- What do you plan to do with the data later?
- Why are you looping infinitely?
- What is the significance of k in the context of your data or how it is calculated?
Save logical array inside another array in a while loop
9 次查看(过去 30 天)
显示 更早的评论
I have a script that runs an infinite "while" loop and creates a 1-row logical array with varying columns in each loop. Now, the variable that contains the information of that logical array is re-written in every loop so I was wondering if there is a way I could store that information in an array outside the while loop. I have tried defining the while loop as an infinite for loop:
for k=1:inf
array=false(1, length(var_pos);
choice_hist(k,:)=[array];
if tf==true
array(var_pos)==true;
end
end
When I run this code I get the error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in test (line 71) choice_hist(k,:)=[array]; ". This makes me think that since the 'array' is changing between 1 and 6 columns in every loop, the table needs to have the same number of columns on each row. Is there a way to bypass that?
2 个评论
Cam Salzberger
2018-10-31
There are a lot of suggestions that can be made here, but I think it would probably help if you gave us some context here. Infinite loops and storing variable size arrays generally aren't the best way to do things for a good reason. So I'm specifically wondering about:
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!