I am trying to create a MATLAB GUI that will display the result of an ADC in SIMULINK. Here is a picture of the setup I have in Simulink. I use a Display block to output the ADC. I want the value of the Display block be passed to a label I have in my GUI. I use the code:
get_param('Simulink_ModelSim/Power1','value')
but an error appears. I don't understand what is happening. When I pass 1 bit with a switch, it goes well. but with displays it does not. Please Help. TIA
Related
I have made a Gui program that I compile to EXE application which lots csv file into graph data. I buit a save button but I do not know how save figure with different name each time cause (savefig anduisave both uses matlab program). I am posting my code below if anyoff you guys figure out how to save gui figue into image or anything that does require matlab to open. Last function is the callback function for save button.
function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
%savefig
If you are trying to save a kind of image from your figure, then the best option which supports many aspects, is using print function.
I have already done this in a compiled app and it works perfect. Using print function you can set different file type(vector formats like *.svg are also supported), resolution(dpi), and so many others.
Although you can use print function directly on the figure, but I found that the best way (More Customization like removing or adding some objects and changing many options) is to follow this steps:
Create another figure with Visible='on' but a position that is out of screen with the same width and height of Main Figure.
normalized position = [-1, -1, ?, ?]. (Create this figure in start up and don't destroy it until your app exits, let call it Print Figure).
Copy your figure content (or the parts you are interested in) using copyobj to that figure (you may need to set Parent property of some key objects like panels to this new figure). They would look exactly as they look in the main figure, because they have the same properties. you can add or remove some objects in this step.
Change aspect ratio of "Print Figure" for a better output.
Print this figure with all options (file format, dpi, ...) you need. in my own GUI i allowed the user to change this settings with an input dialog.
In my app i used functions like winopen to show the output, and output directory to the user, when the print task was done. Print process takes some time, specially if dpi is huge, so it is also a good idea to inactivate buttons and show wait cursor.
Update:
a simple usage would be:
print(MainFigure, 'myFileName', '-dpng', '-r300')
I am attempting to implement a servo motor with feedback control program in MATLAB for multiple servo motors. The objective is to read servo(s) analog output, compare with a user value from slider bar(s), write the new position to the servo, and continue to write or monitor analog output to ensure servo maintains last user value. I am having trouble because I cannot figure out the optimal flow to always keep the GUI open and accepting user values while a while loop runs in the background. Below is the general structure that I would like the code to output:
test_gui %calls GUI figure with slider bar
GUI window with Slider bar pops up
%Callback for when user slides bar
function slider(i)_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
load('user.mat'); %Load previous user input
sze=size(user,1);
user(sze+1,1)=get(hObject,'Value'); %Add new user input to previous input
save('user.mat','user') %Save variable to be accessed by outer loop
'user' is passed into a continuous while loop that writes servo position
while user ~= 'c' %Continue to run until close window callback
load('user.mat'); %load user input from callback
Write_Servoi(a,user(end,:),add,speed,pinin,myServo) %Writes to servo(s) based on last input, allows servo(s) to maintain position if torqued out of position
end
During this while loop, I would like the user to be able to continuously change the slider and send this slider value into the while loop to be written to the servo. However, I cannot figure out how to update user when in the while loop.
If anyone has any ideas on how to get this to work, please let me know. I would greatly appreciate any help. I am open to changing the structure, as long as the objectives above are satisfied.
Robert
To update the user variable, you'll need to make sure it is properly loaded. Calling load with no output does not always load your variable into the function workspace.
Instead of load('user.mat');, you'll need to load your file as a structure and then retrieve your variable from the structure. To accomplish this, do the following:
s=load('user.mat');
user=s.user;
I am using Psychtoolbox to display on a screen as part of an interface. I create a blank screen with [win,Rect]=Screen('OpenWIndow',etc.etc...) in my main script. I would like to use a function call later on in the script to update the screen, but I have no idea how to get the values in and out of the function to change the Screen.
So something like:
%main script
[win,Rect]=Screen('OpenWIndow',0,[0 0 0],[0 0 1280 1024]);
%do other processing (in my case communicating with another computer.)
DrawStuff() %function that takes variables from script and updates the screen
% continue script
Screen('Flip',win) is what you are looking for, but you need to issue some drawing commands for it to show anything.
Please read the file PsychDocumentation/PTBTutorial-ECVP2013.pdf in the psychtoolbox distribution to understand the basics of stimulus presentation.
My function calls code from other functions I did not write those but I know what they do. One of them is .p Matlab file with obfuscated content.
I am doing batch processing of a number of files. I want to write the figures directly to file without display. So I can go through them separately.
Any ideas on how to achieve this.
Thanks!
Script to save matlab figures to a specified directory
The above link works but I still want to avoid displaying the figures at all. Directly print to file. But the work around can simply close all open figures after that loop.
In your script, as soon as you create the figure, set its visibility to off.
For example:
figure(28732);
set(28732,'visible','off'); %Now the figure is not shown
You can now work with the figure, plot, save etc, without the visual clutter or system overhead of displaying it.
If you want ALL of your figures to start without visibility, you can set the default property, as follows:
set(0,'DefaultFigureVisible','off').
This will cause all generated figures to be generated without visibility. (Note, this will be very confusing is you forget that this property is set.)
You should still close the figure as soon as possible in the script, as a part of good memory management.
I have made an program that can display many outputs in same textbox in matlab.
The main program do looping and the GUI catch the output and display the outputs in same textbox. But the problem is that the output is displayed in new line.
Iwan to display the output just in one line..
How to do it?
Here is my Gcode to display the output in the GUI.
letterr = ProcessOutput;
set(handles.text4,'String',letterr);
you can use
set(handles.text4,'String',strjoin(letterr));
depending on the version of matlab you are using, this function is implemented or not. If not, you can get it from here:
File-exchange: strjoin