Hello,
[This is a rather long introduction to the problem, the beginning of the question is marked as QUESTION]
first things first, I am relatively new to matlab. For the past three days, I have been working on a script that let's me define and plot the fits of two data sets against each other from another file. The idea is to just call the script, tick all check boxes that you want to have ticked and let it go through with plotting the figure.
It is intended to limit user-input to decision and vector-definition, without having to write the actual code for
0) A menu to jump to skip certain steps and jump elsewhere
1) Defining the vectors
2) Fitting them
– all standard fits from matlab will be included, and if I get it to work, an option for custom definition of fits
3) Plotting the fits
4) Defining axes, title etc of the plot (not yet included)
Now, till now I´ve been using the goto()-script that has been uploaded by Husam Aldahiyat to the File Exchange. And it worked for ~70% of the time. It is used to navigate and skip certain parts in cases. I've included the unmodified version of it that is used. In addition, here's the link to the Exchange-page
It is used to skip the Definition and/or Fitting Parts, for instance if a typo in an axis description has been made. This would normally force one to call the script again, which defeats its purpose a bit.
It is possible to run the script once successfully (till where it is right now, at least). But if I try to jump to certain sections, goto either drops me somewhere else or gives me an error, that at least one END is missing inside the goto()-code. I can't find it, although I may just
QUESTION
As I am aware, goto can create a huge mess, which is why you all would scream at me not to use it and use functions instead. I tried wrapping my head around them, but for some reason I can't figure out how to do it with those. I tried to find a way to navigate as I am doing right now, but can't get these functions to work. What I basically need is a function that I can call that skips to any point in the script that is labeled as LABEL xyz.
I thought of just creating one huge switch-case-system and just type every possible version out. That would certainly be possible, but I don't think it'd be neither the most efficient nor enjoyable mean of doing this. Not to mention that that would amass to a shitton of code to sift through if something DOES go wrong. By now, I am fed up with this. I shortly meddled with the idea pitched by Jan as an answer to another persons goto-question (cf. Accepted Answer Script), but I don't know how to get it to work for what I have in mind.
To try and get the first step explained, here is a mindmap that shows where everything is supposed to lead.
Bottom Line is, I don't know nor understand the matlab functions well enough ~or at all~ to code this network, and goto() breaks down.
I`d be glad if someone could help me with this.
Resetlist={'Repeat','No','Yes','Jump to:'};[resetindx,tf0]=listdlg('ListString',Resetlist,'PromptString','Reset?','Name','Reset?','SelectionMode','single','ListSize',[160 60]);switch resetindx case 1 %Repeat
goto ('RepeatReset') %%goes to Line 38
return case 2 %No
goto ('Fitting') %% Line 117 This breaks when pressed at all, no matter if there're vectors defined already or not
return case 3 %Yes %% just runs till Line 68
clear all; %has to be renamed into clearing all Variables of this script, so that the original one stays intact.
close all; clc case 4 SectionofInterest={'Section 1: Vector Definition','Section 2: Fitting','Section 3: Graphic Settings'}; [jumpindx,tf0]=listdlg('ListString',SectionofInterest,'PromptString','Go where?','Name','Go where?','SelectionMode','single','ListSize',[160 50]); switch jumpindx case 1 %% just runs till Line 68
case 2 goto('Fitting') %% LIne 117
return endend%%%------------------- below is a part of code later on.
%% Section 2: Fitting % LABEL Fitting %% Line 117
FitListGeneral={'PolyX','ExponentialX','FourierX','GaußianX','PowerX','RationalX_X','Weibull','InterpolantX','Custom_not_working'};[FitindxGeneral,tf1]=listdlg('ListString',FitListGeneral,'PromptString','Select Degree','Name','PolyX','SelectionMode','single','ListSize',[160 130])switch FitindxGeneral case 1 Fitlist={'Poly1','Poly2','Poly3','Poly4','Poly5','Poly6','Poly7','Poly8','Poly9'}; [Fitindx, tfx2]=listdlg('ListString',Fitlist,'PromptString','Select Fittype','Name','Fittype-Selection','SelectionMode','Single','ListSize',[160 130]) switch Fitindx case 1 [NumRows,NumCols]=size(maty) clear NumColsfor k=1:1:NumRows hold on Fit{k}=fit(matx(k,:)',maty(k,:)','poly1') plot(matx(k,:),maty(k,:),'o') plot(Fit{1,k},'') hold on pause(1) enddisp('For the fits of the different functions, open the "Fit"-cell') case 2 [NumRows,NumCols]=size(maty) clear NumCols%%-- And below is the error-message you get when trying to say "No" to resetting, and then choose polyX --> poly1
Error using goto (line 638)Error: At least one END is missing: the statement may begin here.Error in Plotter_v04_Testbranch_Question (line 47) goto ('Fitting') %% Line 117 This breaks when pressed at all, no matter if there're vectors defined already or not
Best Answer