Creating multiple column legend [duplicate] - matlab

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!

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)

MATLAB: how to reuse plot options? [duplicate]

This question already has answers here:
Is that possible to assemble several options and pass to the plot function in matlab
(4 answers)
Closed 7 years ago.
I have the following plot:
patch('Vertices',rocket_point_cloud,'Faces',rocket_faces,...
'FaceColor','red','EdgeColor','none',...
'BackFaceLighting','reverselit',...
'SpecularStrength',1,'DiffuseStrength',1)
I would like to reuse the plot options, i.e. reuse:
'FaceColor','red','EdgeColor','none',...
'BackFaceLighting','reverselit',...
'SpecularStrength',1,'DiffuseStrength',1
Is it somehow possible to store the above in a variable, e.g. my_options and later on do:
patch('Vertices',other_cloud,'Faces',other_faces,my_options)
Thanks for your help!
Sure. Just define your options in a cell array,
my_options = {'FaceColor','red','EdgeColor','none',...
'BackFaceLighting','reverselit',...
'SpecularStrength',1,'DiffuseStrength',1};
and then expand that cell array into a comma-separated list via curly-brace indexing:
patch('Vertices', rocket_point_cloud, 'Faces', rocket_faces, my_options{:})

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.

Why Matlab shows "Index exceeds matrix dimensions."? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here is my matlab code:
gg=imread('fsu_Westcott.jpg');
data1=gg(:,1);
histArray1=zeros(1,256);
x=0:1:255;
for n=1:length(data1)
histArray1(1,data1(n)+1)=histArray1(1,data1(n)+1)+1;
end
for n=1:length(data1)
number1=sum(histArray1(1:n));
end
plot(x,number1,'r')
Why it shows "Index exceeds matrix dimensions."? before I finally plot? I am new and thanks in advance! :)
On the line:
number1=sum(histArray1(1:n));
you are asking for cells 1 to n of array histArray1 but n goes from 1 to length(data1) which is larger than the length of histArray1 (256). So it is out of bounds.
This loop:
for n=1:length(data1)
number1=sum(histArray1(1:n));
end
seems unnecessary if you want to plot the histogram anyway.
One more tip, there is a function called hist which you could use to both compute the histogram and plot the result in a barchart in one line:
hist(data1(:), 0:255)
To me it looks like you have a couple things you'll want to fix. To fix the error on the line Simon pointed out, I think you'll want to have your 2nd For loop going from 1 to length(histArray) (or 256) instead of length(data1). The second problem I see is that in the 2nd For loop you aren't building an array--you're just redefining the variable number1 over and over. You should probably put number1(n)=sum(histArray1(1:n)); inside that for loop instead. This doesn't have to do with the error you're seeing but it might help you get what you want out of the script.

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

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.