How do i clean up dependent if statement?

10 Ansichten (letzte 30 Tage)
Andrew P Raudabaugh
Andrew P Raudabaugh am 31 Mär. 2018
Bearbeitet: Andrew P Raudabaugh am 31 Mär. 2018
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,

Akzeptierte Antwort

David Fletcher
David Fletcher am 31 Mär. 2018
Bearbeitet: David Fletcher am 31 Mär. 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 Kommentar
Andrew P Raudabaugh
Andrew P Raudabaugh am 31 Mär. 2018
Bearbeitet: Andrew P Raudabaugh am 31 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by