Save logical array inside another array in a while loop

9 views (last 30 days)
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
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:
  1. What is the significance of the information contained in the array?
  2. Why does it change size every iteration?
  3. What is the expected data contained in the array?
  4. What do you plan to do with the data later?
  5. Why are you looping infinitely?
  6. What is the significance of k in the context of your data or how it is calculated?
Milton Logothetis
Milton Logothetis on 31 Oct 2018
Hello Cam, Essentially I have created a listdlg box that acts as a plotting mechanism. The user can choose a parameter on that list and it will be plotted. The way that I have implemented this is by creating an array of logical zeros with size (1,length(parameter_position_in_list)). When the listdlg gets an output, that is say the 3rd item from the top, then it converts the zeros array into [0 0 1]. The loop is run indefinitely so that after each parameter choice the listdlg pops up again and the user can plot another parameter on the same plot. What I want to do is to somehow store that array in order to be able to un-plot a parameter if the user clicks on an item that is already plotted, because so far it plots whatever the user clicks on again and again.

Sign in to comment.

Answers (0)

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!