How do i clean up dependent if statement?

10 ビュー (過去 30 日間)
Andrew P Raudabaugh
Andrew P Raudabaugh 2018 年 3 月 31 日
編集済み: Andrew P Raudabaugh 2018 年 3 月 31 日
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 日
編集済み: 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 Center および File ExchangeWhos についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by