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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by