How do i clean up dependent if statement?

10 次查看(过去 30 天)
Hello all,
I have a section where I ask the user to enter a few parameters using inputdlg. The number of dialog boxes presented is dependant on a number of shims which is asked for at the beginning. Is there a more efficient way of doing this so I don't have to put an upper limit on the number of prompts will be asked for? Please see the attached m.file
Cheers,

采纳的回答

David Fletcher
David Fletcher 2018-3-31
编辑:David Fletcher 2018-3-31
    shims=zeros(num,3) %Matrix for storing shim data 
    s_top=inputdlg({'shim OD in m','shim ID in m','shim Thickness in m'},'Top Shim',[1,60])';  %#ok<NASGU>
    shims(1,:)=str2double(s_top);
    %This replaces the existing block
    for iter=2:num
        strResponse=inputdlg({'shim OD in m','shim ID in m','shim Thickness in m'},strcat(num2str(iter),' from Top Shim'),[1,60])'; 
        shims(iter,:)=str2double(strResponse);
    end

shims are all stored in the one matrix which will make it easier to apply functions to the entire data set rather than messing around with separate variables. The top shim could probably also be rolled into the loop, but it needs some playing around with the message. I'm sure you get the idea.

  1 个评论
Andrew P Raudabaugh
编辑:Andrew P Raudabaugh 2018-3-31
David, Thanks for the quick response. How you answered it makes the question look silly in hindsight. As you can tell, I have no idea how to use matrixes well. Thanks, hopefully, I will be able to get to your level someday.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by