Workspace update

1 view (last 30 days)
Casper Hugel
Casper Hugel on 23 Oct 2011
for some time now I have been trying to automatically update the workspace, unfortunately without result.
THis is the case:
I use a GUI in which I have installed a few axes which plot a variety of data. there are also a few boxes which can be adjusted. These inputs ( the x and y coordinates of a circel on a plane) are then used to calculate the data used in the graphs. The calculations are done with several programmes. THe gui links to a driver file, which also links to a paramater file. THis parameter file is actually used to compute the coordinates. I use the command run to run all the programmes.
Now the problem is that I have to actually run the parameter file with the calculation in order to obtain the coordinates I specified earlier in the GUI, for some reason this doesnt seem to work without me having to run the programma manually. Is there anything I can do to do this automatically, so that when I click on plot, the gui alteres the graphs for the specific coordinates I specified in the boxes in the gui?
CHeers,
Casper

Accepted Answer

Casper Hugel
Casper Hugel on 23 Oct 2011
Then what should I ask, if everything I post is to vague... Gosh...
I doubt that you cannot watch the tinipic pictures I sent. Even when I am not logged in onto tinypic I can still view the pictures. Anyway, I will try to explain it again. THe pictures served as an illustration to make it easier for you to understand... Can I sent them to you by email if that is more covenient?
ALright, this is the case:
I am trying to simulate a car with a mass-demping system and pendulum installed on top of the car. This car ''rides'' on a 3D plane with mountains and valleys. THe task is to keep the upper part of the car horizontally while the car ''drives'' on top of the plane.
In order to simulate this I am using: * m-files * a simulink model * a GUI
The GUI shows one grpah with the plane, on the plane a circle is visible. THis is the route the car follows. In the GUI I want to be able to adjust the x and y coordinate and the radius of the circle. The GUI also shows three other graphs which plot the velocity, angle of the upper plate and the height of the car in respect to the XY plane. # # In the GUI.m I have specified the following inputs. When you press this button in the GUI itself, the graphs should automatically change to the x and y coordinates and the radius I specified in the GUI earlier.
% --- Executes on button press in edit_pushbutton.
function edit_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to edit_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
invoer.r = str2num(get(handles.edit_r, 'String'));
invoer.x_co = str2num(get(handles.edit_xco, 'String'));
invoer.y_co = str2num(get(handles.edit_yco, 'String'));
invoer.sn = str2num(get(handles.edit_sn, 'String'));
setappdata(0, 'invoer', invoer);
I then run my driver file:
%%Driver file runnen
run Driver_eind
%%get driver answers
uitvoer = getappdata(0, 'uitvoer');
and I plot my graphs.. This is actually the graph which plots the landscape, or the plane on which the ''car'' rides.
%%plotten landscape
axes(handles.axes_landscape)
cla
hold on;
plot3(x_route,y_route,z_route,'k','LineWidth',3);
surf(data);
xlabel('x-as [m]');
ylabel('y-as [m]');
This is another graph which plots dx = velocity and x= height
%%plotten
axes(handles.axes_snelheid)
cla
plot(resultaat.tout,resultaat.dx,resultaat.tout,resultaat.x);
legend('snelheid','afstand');
xlabel('t [s]')
ylabel('snelheid [m/s]')
title('snelheid/afstand wagen')
Oke, the GUI m file is slightly longer, with some more graphs plots being specified, but that is not the point.
The driver file is designed as follows, it first collects the x and y coordinate and the radius of the circle;
invoer = getappdata(0, 'invoer');
straal = invoer.r;
x_mid = invoer.x_co;
y_mid = invoer.y_co;
sn='invoer.sn';
it then runs the parameter file, in this file the new trajectories are beeing computed based on the x and y coordinate and the radius
%%Laad parameters
run Parameters_7;
%model parameter
teind =11;
additionally the simulink model is being opened and simulated, to compute the bahavior of the massa demping system and the pendulum.
%%simuleer
open('opdracht5.mdl')
sim('opdracht5');
alright, now the parameter file. as mentioned above, the x and y coordinates and radius are being used to determine the car its trajectory
x_route = x_mid- straal*cos([0:0.001:2*pi]);
y_route = y_mid - straal*sin([0:0.001:2*pi]);
z_route = interp2(ZI,x_route,y_route);
s(1) = 0;
for j=2:length(x_route)
s(j) = s(j-1) + sqrt((x_route(j)-x_route(j-1))^2+(y_route(j)-y_route(j-1))^2);
end
parameters.baan.x=s;
parameters.baan.y=z_route;
Right. And now the problem.... THe problem is that the GUI doesn't automatically alters the graphs when I have altered the x and y coordinates and radius. That is because the workspace isn't beeing updated, only when I first run the driver file, the workspace is being updated. When then the graphs are being plotted they are altered to the specified variables for x, y and the radius.
  3 Comments
Casper Hugel
Casper Hugel on 23 Oct 2011
Hi!
thank you for your answer, I can see why this is causing the system to 'malfuction'. I know that it is better to come to a solution yourself, but I have spend my last night, and one entire day to solve the problem. And to be honest with you, I am done with it. Is there any way to just simply solve this problem...? Because my deadline for this project is on tuesday and I also have to learn for my exams next week, so I cant really afford to spent much more time in finding a solution... or rebuilding the whole GUi, mfile and model..
Casper Hugel
Casper Hugel on 23 Oct 2011
oops, I clicked on the accept answer button...

Sign in to comment.

More Answers (4)

Fangjun Jiang
Fangjun Jiang on 23 Oct 2011
It's not very clear in your question. I suspect it is an issue with the function workspace and MATLAB base workspace. You are probably looking for functions like evalin(), assignin().

Casper Hugel
Casper Hugel on 23 Oct 2011
*BOLD TEXT*I wish there was a way to make it more clear, but unfortunately it is quite a complex system. Shall I post the file itself so you can have a look?
Hmm that doesnt seem to work, I can post some critical lines:
This part is from the GUI and links the coordinates, radius and a number to the other files.
  • invoer.r = str2num(get(handles.edit_r, 'String'));
  • invoer.x_co = str2num(get(handles.edit_xco, 'String'));
  • invoer.y_co = str2num(get(handles.edit_yco, 'String'));
  • invoer.sn = str2num(get(handles.edit_sn, 'String'));
  • setappdata(0, 'invoer', invoer);
  • run Driver_eind
  • uitvoer = getappdata(0, 'uitvoer');
  • axes(handles.axes_landscape)
  • cla
  • hold on;
  • plot3(x_route,y_route,z_route,'k','LineWidth',3);
  • surf(data);
  • xlabel('x-as [m]');
  • ylabel('y-as [m]');
This part receives the data (Driver eind) and runs other progammes to compute values.
  • invoer = getappdata(0, 'invoer');
  • straal = invoer.r;
  • x_mid = invoer.x_co;
  • y_mid = invoer.y_co;
  • sn='invoer.sn';
  • run Parameters_7;
  • open('opdracht5.mdl')
  • sim('opdracht5');
This part is from the GUI and links the coordinates, radius and a number to the other files
  • x_route = x_mid- straal*cos([0:0.001:2*pi]);
  • y_route = y_mid - straal*sin([0:0.001:2*pi]);
  • z_route = interp2(ZI,x_route,y_route);
  • s(1) = 0;
  • for j=2:length(x_route)
  • s(j) = s(j-1) + sqrt((x_route(j)-x_route(j-1))^2+(y_route(j)-y_route(j-1))^2);
  • end
  • parameters.baan.x=s;
  • parameters.baan.y=z_route;
%model parameterI hope this gives you a slighter better view on the programe
  1 Comment
Jan
Jan on 23 Oct 2011
Please use standard code formatting.

Sign in to comment.


Jan
Jan on 23 Oct 2011
The question is still not clear.
Usually callbacks of AXES or the UICONTROLs are used to start other functions after a user-interaction. These callbacks obtain the handle of the calling object, such that you can access the the properties or children of the object directly, or you can gain access to the other objects of the GUI by using GUIDATA or "get(ancestor(ObjectHandle, 'figure'))".
Such methods are explained in Matt Fig's 41 GUI examples.

Casper Hugel
Casper Hugel on 23 Oct 2011
Hi,
since I have no idea how to use standard code formatting, I decided to make some screen shots of the situation... I recon this is clear enough to understand the problem:
  1 Comment
Jan
Jan on 23 Oct 2011
At least I cannot see pictures hosted at tinypic. In addition posting code as pictures is not helpful, because citing needs to re-type the text.
The code formatting is explained exhaustively in the "Markup help" link above the box for writing the text. Either start a new sction with a blank line and insert two leading spaces in each line, or type the code, mark it with the mouse and hit the "{} code" button. See also: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup .
Posting the code will not clarify the question. Terms like "gui links to a driver file" are too vague.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!