- 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 views (last 30 days)
Show older comments
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 Comments
Cam Salzberger
on 31 Oct 2018
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:
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!