MATLAB: how to get the list of figures [duplicate] - matlab

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I get the handles of all open figures in MATLAB
The situation is following. I run a couple of tests, which plot a lot of figures. I would like to convert them to pdf and compile into one file. Since each time I may get different type of plots and different number of plots, I need to get the list of all figures in current matlab session or workspace. Is this doable?
Thanks

h = get(0,'Children');
will put the "handles" to the figures you currently have in the variable h. get(handle) and set(handle,...) are gigantically useful in general. The handle 0 points at the root of the display, so all the figures on the display are the root's Children.

Related

plotting results from different files into on figure by using different colors [duplicate]

This question already has answers here:
Plot different colors
(2 answers)
Closed 5 years ago.
I have some log files and in these log files there are some timestamps from different smartphones. I plotted each log file into different figures. Lets say there are 3 smartphones and each has a specific number like 10, 11, 12 and each smartphone's result keeps in one log file.
Basically what I want to do is, showing the results of these three log files into one figure by using different colors for each log file. Is there anyone who knows how to do it?
EDIT
n=size(allTimeStamps{1},2);
figure(1);
hold on;
for i=1:n
plot(allTimeStamps{1}{i},mod(allTimeStamps{1}{i},0.3),'Color',colorspec{indexOfFile});
end
title(logFileName);
You can use the function lines to get the default colors of Matlab in order. This function creates a matrix of n-by-3 that each row within is a new color. However this is good up to 7 colors, otherwise, you can choose another colormap, or use this suggestion.
Here is an example:
data = reshape(1:99,[],3); % some arbitrary data
n = size(data,2);
figure;
hold on;
col = lines(n);
for k = 1:n
plot(data(:,k),'Color',col(k,:));
end
hold off
(This code is only for demonstrating, in this specific case you don't even need a loop, because plot(data) will give the same result)

Loading (and computing/plotting) multiple .MAT files [duplicate]

This question already has answers here:
How can I load 100 files with similar names and/or string in just one step in MATLAB?
(3 answers)
Closed 6 years ago.
I have 4 .MAT files that I need to run similar functions on, and plot on same graph. Problem is, if I load first file, it only runs on that file. After the "load" function, there are 163 lines of code to repeat. Some answers I have seen require .Mat files with similar naming convention.
File names are:
M1_N_o
M2_S_o
M3_N-b
M4_S_b
Only a little info is given. If you could provide the code it will be more helpful. So I am assuming a lot of stuffs.
I am assuming that all files have the same variables with same dimensions
First rename files
M1_N_o.mat,M2_S_o.mat,M3_N-b.mat,M4_S_b.mat
to
M1.mat,M2.mat,M3.mat,M4.mat
Matlab Code:
figure
hold on
numberOfFiles=4;
for fileIndex =1:numberOfFiles
fileName=strcat('M',num2str(fileIndex),'.mat');
load(fileName);
% your 163 lines of code
% do your plots
end
hold off
If you dont want to rename the files then
figure
hold on
fileNames={'M1_N_o.mat' ;'M2_S_o.mat'; 'M3_N-b.mat'; 'M4_S_b.mat'}
for fileIndex =1:size(fileNames,1)
load(fileNames{fileIndex});
% your 163 lines of code
% do your plots
end
hold off

How to Load a .txt file into an matrix of matlab [duplicate]

This question already has an answer here:
read from a text file and load it into a matrix in matlab [duplicate]
(1 answer)
Closed 7 years ago.
Good day.
I would like to know how to load a .txt file in matlab. What I want is to work with text classification and guess the first thing to do is load devo my data in matlab .... but when I try to generate many files .my I just want an array containing my text.
Greetings and thanks in advance.
There's multiple functions that do that: importdata,textscan,fopen,dlmread etc.
I do not understand much from your question, but begin by reading through these documentation pages and try them to see which works best for you.

Creating multiple column legend [duplicate]

This question already has answers here:
How can I customize the positions of legend elements?
(5 answers)
Closed 4 years ago.
I use MATLAB to draw a graph. The legends are too big and cover a part of the graph. I want to split the entries of the legend in two columns. I saw some solutions on the net that explain how to change the functions to display the legend in multiple columns. However, my program reads the data from an Excel file and their solutions don't work for me. Could anybody please help me to solve this issue? Sorry if my question is naive, I'm not good in MATLAB.
Here is my code:
A=xlsread('C:\temp.xlsx','A1:A10');
B=xlsread('C:\temp.xlsx','B1:B10');
C=xlsread('C:\temp.xlsx','C1:C10');
D=xlsread('C:\temp.xlsx','D1:D10');
E=xlsread('C:\temp.xlsx','E1:E10');
F=xlsread('C:\temp.xlsx','F1:F10');
G=xlsread('C:\temp.xlsx','G1:G10');
plot(A,B,A,C,A,D,A,E,A,F,A,G)
hold on;
axis([10 100 -10 0])
xlabel('length')
ylabel('BER')
legend('AAAAAAAAAA','BBBBBBBBBB','CCCCCCCCCC','DDDDDDDDDD','EEEEEEEEEEE','FFFFFFFFFF')
Here are two different links to matlab-files that should solve your problem:
ColumnLegend
GridLegend
The creation of the legend should be independent on how you read your data, so the fact that you read your data from Excel should not give you any problems!

variable becomes undeclared after some iteration in matlab [duplicate]

This question already has answers here:
Is it possible to have a workspace variable that persists across a call to clear?
(2 answers)
Closed 9 years ago.
Does MATLAB keep some variables after clearing?
Matlab: Free memory is lost after calling a function
My question is related to this post but some changes are there.
I have to use the output (the outputs are matrices generated, i.e. i am generating small matrices in every iteration) produced by previous large program, in my next iteration of large program, so when i am using the technique mentioned in the post, i am getting error that " Reference to a cleared variable", i need to keep some of the variables and some matrices generated. How to do that?
Sometimes the error occurs after 1 iteration only
Thanks
You can clear specific variables in the workspace with:
clear myvarname
You can also clear functions that might be holding persistent variables with:
clear myfunname
So - you should work out which ones you don't want (type whos to see variables in the workspace, or in a breakpoint) and clear the ones you don't need.
Another option would be to save the ones you do want, use the clear method you mentioned, then re-load.