Array Keeps creating 0's in my Loop
1 回表示 (過去 30 日間)
古いコメントを表示
The issue I am facing is my array (B) keeps reseting or losing the values that is being saved into it. I believe the issue is within the first three lines where I attempt to convert info(cell) into counter(double array)
B=[];
%I believe the issue lies here will I am getting the information for how
%long i want the loop to be
info=inputdlg('How many variables do you want to create a ratio for (2-5)');
convert1=cell2mat(info);
counter=str2double(convert1);
%I have done tests if I change counter to a number say '3' The B array
%will store information correctly
for p=1:1:counter
list = {'1','2','3','4','5'};
[indx,tf] = listdlg('PromptString',sprintf('Select Variable----->1=Resident , 2=Education , 3=Office , 4 =Toilet, 5=storage')...
,'ListSize',[500,250],'SelectionMode','single','ListString',list);
B(1,counter)=indx;
end
0 件のコメント
採用された回答
David Fletcher
2021 年 5 月 10 日
Your problem lies in the line
B(1,counter)=indx
counter is the max value of the loop and doesn't change - you should use the loop iterator p instead
B=[];
%I believe the issue lies here will I am getting the information for how
%long i want the loop to be
info=inputdlg('How many variables do you want to create a ratio for (2-5)');
convert1=cell2mat(info);
counter=str2double(convert1);
%I have done tests if I change counter to a number say '3' The B array
%will store information correctly
for p=1:1:counter
list = {'1','2','3','4','5'};
[indx,tf] = listdlg('PromptString',sprintf('Select Variable----->1=Resident , 2=Education , 3=Office , 4 =Toilet, 5=storage')...
,'ListSize',[500,250],'SelectionMode','single','ListString',list);
B(1,p)=indx;
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!