hey guys
im triyng to build a plot in gui witch get from user the x scale and jumps , y scale and jumps , style and color
for some reason im not sure if im getting it right , can someone give me some lead for it ?
thx!
the code ( only the sector when pusing the plot button)
% Button pushed function: plotButton
function plotButtonPushed(app, event)
Xdata= (get(app.XbeginEditField):get(app.XendEditField):get(app.XjumpEditField));
Ydata= (get(app.YbeginEditField):get(app.YendEditField):get(app.YjumpEditField)) ;
LineStyle= get(app.StyleEditField);
Color= get(app.ColorEditField);
plot(Xdata,Ydata,LineStyle,Color);
end
end

 Accepted Answer

Three main things to be aware of:
1) In MATLAB, using the colon operator to specify a vector: the syntax is "begin:jump:end" rather than "begin:end:jump"
2) Usually you will use get with two input arguments: first the object and second the property. Using only the first argument will return a struct of all properties for that object.
3) With edit boxes, you will typically get the 'String' property, and then convert that to a numeric value with str2num or str2double if necessary.
So with those things in mind:
% Button pushed function: plotButton
function plotButtonPushed(app, event)
Xdata= (str2double(get(app.XbeginEditField,'String')):str2double(get(app.XjumpEditField,'String')):str2double(get(app.XendEditField,'String')));
Ydata= (str2double(get(app.YbeginEditField,'String')):str2double(get(app.YjumpEditField,'String')):str2double(get(app.YendEditField,'String')));
LineStyle= get(app.StyleEditField,'String');
Color= get(app.ColorEditField,'String'); % Note: I'm assuming your program expects a string color specification, e.g., 'k', 'g', 'r', etc.
plot(Xdata,Ydata,LineStyle,Color);
end

2 Comments

thank you man
the only problem im trying to work with the app and get this Error using matlab.ui.control.NumericEditField/get
Unrecognized property String for class NumericEditField.
i thought the problem is that i didnt wrote the color and line style right but is seems like he wont recognize one of my numbers
Apparently AppDesigner allows different types of edit boxes: EditField and NumericEditField. I don't know which type(s) you have, but StyleEditField should be an EditField (since a line style is non-numeric), ColorEditField could be either one depending on how the line color is specified, and the others (X,Y) can be NumericEditFields.
With EditField or NumericEditField, you'll get the 'Value' property (rather than the 'String' property - which is for edit boxes made in GUIDE), and that'll be a numeric value for NumericEditField or a string (or character vector) for EditField. So there's no need to convert a string to a number for NumericEditField. So, assuming that the ones for X and Y start, jump, end are all NumericEditFields and the others are EditFields, the code would look like this:
% Button pushed function: plotButton
function plotButtonPushed(app, event)
Xdata= (get(app.XbeginEditField,'Value'):get(app.XjumpEditField,'Value'):get(app.XendEditField,'Value'));
Ydata= (get(app.YbeginEditField,'Value'):get(app.YjumpEditField,'Value'):get(app.YendEditField,'Value'));
LineStyle= get(app.StyleEditField,'Value');
Color= get(app.ColorEditField,'Value'); % Note: I'm assuming your program expects a string color specification, e.g., 'k', 'g', 'r', etc.
plot(Xdata,Ydata,LineStyle,Color);
end

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 7 Dec 2021

Commented:

on 8 Dec 2021

Community Treasure Hunt

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

Start Hunting!