How do i clean up dependent if statement?

10 visualizzazioni (ultimi 30 giorni)
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,

Risposta accettata

David Fletcher
David Fletcher il 31 Mar 2018
Modificato: David Fletcher il 31 Mar 2018
    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 Commento
Andrew P Raudabaugh
Andrew P Raudabaugh il 31 Mar 2018
Modificato: Andrew P Raudabaugh il 31 Mar 2018
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.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by