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
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:
  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 2018-10-31
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.

请先登录,再进行评论。

回答(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