Display output in a separate window in MATLAB - matlab

At the end of the execution of my program in MATLAB, the results, stored in a variable are being displayed in the command window. How to display the contents of a variable on to a different window?
Thanks!

Don't know whether this method suits your need, but try this: suppose variable x has the processed information.
strx = num2str(x);set(handles.textboxname, 'String', strx);

Related

Matlab: how to show user possible function inputs like Matlab does using help dropdown

So in Matlab, if you start to type in a function like find( and then wait after the open parentheses, a small yellow popup will appear showing potential input options, like:
find(X)
find(X,K)
find(X,n,direction)
find(__)
So I'm wondering, is it possible to set up my own function so the same happens? I tried copying the find file in the format, so mine looks like this:
%MY_FUNCTION Description of function
% O = MY_FUNCTION(X) returns the output based on the input X.
%
% O = MY_FUNCTION(X,Y) returns the output based on the input Y.
But after saving it, when I type my_function(, all it shows is my_function(...). Is it just not possible for user functions? Thanks for any input!
It is possible to set up these hints for custom functions, but you can't do it in the function .m file. Instead, you need to put the information in a separate functionSignatures.json file in the same directory as the custom function. You can find the official documentation and file specification here.

Simulink matlab function block

How do I display the current value of a variable in the matlab command window? In matlab I usually use disp(var) and it will output the variable value into the command window. However in the MATLAB function block if I were to enter disp('hello') it doesn't show any output in the command window. I am using matlab 2014b.
You idea for displaying output value in the command window is not a good approach to solve your issue. I would suggest you look at scope block if you'd like to see the value during simulation. Or use To Wrokspace block if you'd like to output the value into main workspace.
For debugging your code and design, read and use Simulink Debugger should be helpful.

MATLAB display a link to workspace elements

I'm trying to improve the readability of my outputs. In order to avoid displaying a lot of data, it would be nice to display links that point to specific elements in the workspace (i.e. a variable, a table, a figure, etc.).
Here is a picture to illustrate the idea:
Maybe we can use the disp function, as I know it allows the generation of hyperlinks to a webpage or a file stored in the computer.
Is this possible in MATLAB?
OK, so this is what I came up with. The first thing is to use the openvar function and you specify the variable you want wrapped around in single quotations. This will open up the variable in the Variable Editor (the image that is pictured in your snapshot).
Now, you can also use disp to allow clickable links to run MATLAB commands. Using these two ideas, you would combine the disp linking and openvar to allow a clickable link to execute the openvar function to display your desired variable.
As such, you would basically do this assuming our variable is stored in A:
A = magic(5);
disp('Click on me to show the matrix A')
The disp statement will show you a clickable link, and the desired function to be executed only runs if you click on the link. You can achieve this desired effect by specifying the matlab: keyword inside the URL in the href key, then after it, you write out whatever MATLAB function or statements you want to use. In our case, we use only need to run one function, and that's openvar. Make sure you specify single quotes around the variable you want inside the argument to openvar. The reason why is because the argument to disp is a string, and if you want single quotations to be recognized, you must use a pair of single quotes. As such, in the disp string, there are pairs of single quotes around the variable you want.
Here's the what I get in MATLAB. The steps are reproduced and shown in an animated GIF:

How to set the scope of a variable in a Matlab function

I have observed a strange behavior in running the same code in a Matlab function and in the command window. It's already described in How does scoping in Matlab work? , but I don't understand how I could solve my specific problem.
The code is the following:
exporteddata.m %File created by an external program
%to export data in Matlab format
surface = struct('vertices', [...]) ;
%I can't specify in the external program
%the name of the variable, it's always "surface"
My actual code is:
myfunction.m
function output = myfunction(input)
load(input);
n = size(surface.vertices);
....
When running
myfunction('exporteddata.m');
I get the following error:
??? No appropriate method, property, or field vertices for class hg.surface.
When running the same instructions from the command window or in debug mode, the code works well.
How can I specify in the function that I need the variable surface present in the workspace, not the Matlab function?
First of all, I must point out that surface is a built-in function in MATLAB, so overloading it is just... bad. Bad, bad, BAD!
Having said that, the MATLAB interpreter does a pretty good job at resolving variable names and usually tells them apart from function names correctly. So where's your problem, you ask?
I believe that you're using the wrong function: load is a function that loads data from MAT files into the workspace. It is not fit for m-files. By not executing "exportedata.m" properly, surface has never been created as a variable, so MATLAB identifies it as a function name. If you want to execute "exportedata.m", just type:
exportedata
and if you want to run the file with the filename stored in input, you can use run:
run(input)
By executing run(input) from within myfunction, surface should be created in myfunction's local scope, and it should work.
EDIT:
I've just tested it, and the interpreter still gets confused. so the issue of the variable name resolution remains. Here's a workaround:
function output = myfunction(input)
surface = 0; %// <-- Pay attention to this line
run(input);
n = size(surface.vertices);
Predefining surface allows the interpreter to identify it as a variable throughout your entire function. I've tried it and it works.

How to find call an external function from a GUI in MATLAB?

I have an external function (myfun.m) which will generate 4 images. I want to use a textbox in a GUI to give the function the input parameters (e.g. the name of the original picture), but I have no clue how I can run myfun.m in my GUI. PLease help
First, I would recommend having a different textbox for each input to your function. For example if your function asks for 4 inputs, I would have four textboxes. This will avoid pain on the user's end to format their text input a certain way, as well as pain on your end on parsing a long text string into several inputs.
Second, if your function is within MATLAB's path, then you can call that directly from your GUI no problem just as you would any of MATLAB's built-in functions. You probably want to make a push-button that has a callback to execute that functions.
The way the callback for this function should look is to l