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!