简体   繁体   English

如何在matlab中使用带有for循环的inputdlg

[英]how to use inputdlg with for loop in matlab

have tried searching but can't find anything to help, maybe my problem is too simple!已尝试搜索但找不到任何帮助,也许我的问题太简单了! Anyway, I'm running a nested FOR loop, but the array I save my results to only keeps the last "run" of results.无论如何,我正在运行一个嵌套的 FOR 循环,但是我保存结果的数组只保留最后一次“运行”的结果。 Can someone please help me to store/concatenate the results ?有人可以帮我存储/连接结果吗?

clc 
clear
n = 2;
for aa = 1:n
aa = inputdlg({'Depth from','Depth to','Outer Diameter','Nominal Weight'},'1',[1 7;1 7;1 30;1 30]);
x = [str2num(aa{1}),str2num(aa{2}),str2num(aa{3}),str2num(aa{4})]
end

and the results x =结果 x =

 1     2     3     4

x = x =

 5     6     7     8

I cannot use the first one, want to save all the results and save every iteration in a single variable我不能使用第一个,想要保存所有结果并将每次迭代保存在一个变量中

That is not the way to save the result into an array in a for loop;这不是在 for 循环中将结果保存到数组的方法; separate the looping variable and the array you are storing values in:将循环变量和存储值的数组分开:

clc 
clear
n = 2;
x = zeros(n, 4);
for k = 1:n
    aa = inputdlg({'Depth from','Depth to','Outer Diameter','Nominal Weight'},'1',[1 7;1 7;1 30;1 30]);
    x(k, :) = [str2double(aa{1}),str2double(aa{2}),str2double(aa{3}),str2double(aa{4})];
end

Then if you display x you get something like:然后如果你显示 x 你会得到类似的东西:

x =

     1     2     3     4
     5     6     7     8

Assuming you entered 1 to 4 and then 5 to 8 in the dialog.假设您在对话框中输入了 1 到 4,然后是 5 到 8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM