MATLAB display a link to workspace elements - matlab

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:

Related

How to recognize and print the segmented character

I'm applying some image processing techniques in MATLAB I was able to segment the license plate as show in the figure below:
Now if I apply the followig code in a for loop:
ocrResults = ocr(finalImage);
ocrResults.Text
I'm getting output like VV, u etc that means these characters are not recognized properly. So, how can I fix that? It's not mandatory to use the OCR class so any other solution will also work.
MATLAB's ocr function accepts additional inputs as Name/Value pairs. In your case, to limit the output to numeric values, simply add in the following parameters:
ocrResults = ocr( finalImage, 'CharacterSet', '0123456789' );
However, I'm not certain doing just this will get you the output you desire. It might be helpful to erode the image and add additional blackspace around each character. Take advantage of other possible input parameters which may be added, such as 'TextLayout'.

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.

Why is this error happening: Index exceeds matrix dimensions

I am running a GUI system in MATLAB and I am a beginner with working with GUI's.
The code is extensively long and so I am going to just put in what and where I have things and see if it is enough information for help to be given, thanks.
in my first GUi I have this in the opening function:
HW12_result_bhanford(handles.scan_age, handles.check_athlete, handles.radio_male, handles.radio_female)
this is supposed to be transferring these four variables over to my third GUI named
HW12_result_bhanford
In my second GUI I have this written in the opening function:
age = varargin{1}
athlete = varargin{2}
male = varargin{3}
female = varargin{4}
I then use these four variables(age, athlete, male, female) later in the second GUI and I
assume them to be the equivalent value of the corresponding variable passed from the first
GUI.
When I run everything the error that comes back is Index exceeds matrix dimensions.
if anyone could help me, that would be awesome. If you cannot help without the entire code I understand.
You use varargin if your argument list is variable, and varargin has to be in your function definition.
function HW12_result_bhanford(varargin)
In this case function receive a cell array as an input, so you can get individual arguments with varargin{1} etc.
If you put your arguments together as a structure, you can pass this structure as an argument along.
function HW12_result_bhanford(handles)
But if the function definition has individual arguments, for example,
function HW12_result_bhanford(age, athlete, male, female)
you cannot use varargin, just process the arguments as is.
Read more on how to use VARARGIN.

When using a multiple-output matlab function, do i need to callback all variables?

When using a multiple-output matlab function, do i need to callback all variables? or can I just take the first two variables? (if so..is it not recommended?)
lets say in function.m
[a, b, c] = function( )
in main.m
[var1, var2] = function;
When calling (almost) any function in matlab you can request fewer outputs than it specifies. So, yes the example you give should work perfectly fine.
There are some clever things you can do with this, such as using nargout within a function to see how many output arguments have been requested and only calculating the values that have been requested as an optimisation trick.
It depends on the definition of the function, and exactly which of the outputs you want to get.
Not all the function allow to do it, you can find all the options for each function in the beginning of the help documentation on the specific function.
If you want only the 2nd, or 3rd outputs, and you want also to save the computation-time of the results that does not interesting, you can use ~ option, like this (for versions 2009b and later):
[~, var1, var2]=function
Many functions allow for options to passed that change how the function behaves. I used/wrote various numerical solving functions a bit and one that nice amount of option, for instance is the LSMR function(s).
Otherwise, if you can manipulate the original either introduce an input(s) to do so before or at the end with an inline subroutine to generate the outputs you want.
Or if you can't it will return as either a cell array or a vector and you can pass an anonymous function to generate the desired outputs that way.
Really, can be done many ways. Very contextual.

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