Search this blog!
Thursday, July 5, 2012
Multiple Legend in plot/subplot
I needed multiple legend on a plot for multiple data where data sizes were different. If try classical legend you get the following
figure
p1=plot(I_test(:,:,1),I_true(:,:,1),'r.');
hold on
p2=plot(RGB_test(:,1),RGB_ref(:,1),'g.');
legend( 'true','calculated');
It does not give what I want !! Therefore.....continue reading..
Instead try the following to have different legend
figure
p1=plot(I_test(:,:,1),I_true(:,:,1),'r.');
hold on
p2=plot(RGB_test(:,1),RGB_ref(:,1),'g.');
legend([p1(1) p2(end)], 'true','calculated');
figure
p1=plot(I_test(:,:,1),I_true(:,:,1),'r.');
hold on
p2=plot(RGB_test(:,1),RGB_ref(:,1),'g.');
legend( 'true','calculated');
It does not give what I want !! Therefore.....continue reading..
Instead try the following to have different legend
figure
p1=plot(I_test(:,:,1),I_true(:,:,1),'r.');
hold on
p2=plot(RGB_test(:,1),RGB_ref(:,1),'g.');
legend([p1(1) p2(end)], 'true','calculated');
Legend in Subplot
Acknowledgement : here
subplot(2,2,1);
ph1=plot(rand(10,2),'s-');
subplot(2,2,3:4);
ph2=plot(rand(10,3),'o-');
sh=subplot(2,2,2);
p=get(sh,'position');
lh=legend(sh,[ph1;ph2]);
set(lh,'position',p);
axis(sh,'off');
Monday, March 12, 2012
Matlab: legend in Errorbar
I want to generate an error bar like this. Here, I am comparing three algorithms and I need three legends. Here is how I did it
y = [2.22153808961105 2.49790518623828 2.78257964160148]; % mean or average
e = [0.539408440954881 1.23204940330217 0.813491394996712]; % 1 standard deviation
figure
errorbar(y,e,'r.');
hold on;
h=plot(1,y(1),'ro',2,y(2),'go',3,y(3),'bo');
legend(h,'feature','feature3x3','cluster','Location','Best');
y = [2.22153808961105 2.49790518623828 2.78257964160148]; % mean or average
e = [0.539408440954881 1.23204940330217 0.813491394996712]; % 1 standard deviation
figure
errorbar(y,e,'r.');
hold on;
h=plot(1,y(1),'ro',2,y(2),'go',3,y(3),'bo');
legend(h,'feature','feature3x3','cluster','Location','Best');
Friday, February 24, 2012
In Matlab : Sorting by indexes of another sorting
Imagine, we have the following two array of numbers
A=[ 2 4 6 7 8 8];
B=[ 5 8 2 5 0 5];
Problem:
---------
we want to sort A and then arrange B according to the index of A.
Solution:
----------
>> [sortedA,indexA]=sort(A)
sortedA =
2 4 6 7 8 8
indexA =
1 2 3 4 5 6
>> B(indexA)
ans =
5 8 2 5 0 5
A=[ 2 4 6 7 8 8];
B=[ 5 8 2 5 0 5];
Problem:
---------
we want to sort A and then arrange B according to the index of A.
Solution:
----------
>> [sortedA,indexA]=sort(A)
sortedA =
2 4 6 7 8 8
indexA =
1 2 3 4 5 6
>> B(indexA)
ans =
5 8 2 5 0 5
Thursday, February 16, 2012
How to append in a excel file using Matlab?
Imagine that I have the following excel file called "algoperformace.xls"
Now, I would like to add a new line as the following into this excel file using matlab
How to do that?
----------------------------------------------------------------------------------
Answer:
%% Loading the excel into matlab
[~, ~, alldata] = xlsread('algperformace.xls');
% We will add new entry line into 'alldata' variable and then will write the excel file
% The script will compute the value for algoname, mode, color_diff_95_percentile, max, mean
% adding those values into the cell of 'alldata'
alldata(size(alldata,1),:)={algoname, mode, color_diff_95_percentile, max, mean};
%writing the complete new 'alldata' into the same excel file
xlswrite('algperformace.xls', alldata);
Try your own example :)
| algoName | mode | 95percentile | max | mean |
| Algorithm1 | 13.15153679 | 20.03323188 | 39.52043729 | 15.65858 |
Now, I would like to add a new line as the following into this excel file using matlab
| Neighbor | 2.721678458 | 5.536962451 | 26.63633753 | 3.858783 |
How to do that?
----------------------------------------------------------------------------------
Answer:
%% Loading the excel into matlab
[~, ~, alldata] = xlsread('algperformace.xls');
% We will add new entry line into 'alldata' variable and then will write the excel file
% The script will compute the value for algoname, mode, color_diff_95_percentile, max, mean
% adding those values into the cell of 'alldata'
alldata(size(alldata,1),:)={algoname, mode, color_diff_95_percentile, max, mean};
%writing the complete new 'alldata' into the same excel file
xlswrite('algperformace.xls', alldata);
Try your own example :)
Thursday, February 2, 2012
How may I make the user to browse and select file in Matlab
Very often, Matlab programs need to specify input files or images. Instead of giving the absolute path to that file we may make the user to browse and locate the file.
uigetfile is the function that can do that job. Here is an example.
disp('Select the Reference view');
[filename_ref,pathname_ref] = uigetfile('*.*','Select the Reference view');
if isequal(filename_ref,0)
disp('User selected Cancel')
else
disp(['Reference view: ', fullfile(pathname_ref, filename_ref)])
end
Subscribe to:
Posts (Atom)





