How to make MATLAB start the xtick from the very beginning? [duplicate] - matlab

This question already has answers here:
limit the axes for plotting in Matlab [duplicate]
(2 answers)
Closed 3 years ago.
I am plotting with MATLAB and make MATLAB to put 15 xticks on the x-label. The first xtick doesn't start from the very beginning, though.
xticks([1:15]);
xticklabels({'(1, 2)','(1, 3)','(2, 3)','(1, 4)','(2, 4)','(3, 4)','(1, 5)','(2, 5)','(3, 5)','(4, 5)',...
'(1, 6)', '(2, 6)', '(3, 6)', '(4, 6)', '(5, 6)'});

All you need is: xlim([1:15]);

Related

matlab - audioread produces verbose output and wont stop [duplicate]

This question already has an answer here:
Suppressing Output MATLAB
(1 answer)
Closed 7 years ago.
I am using matlab and trying to plot a spectrogram from an audio file. The problem is that audioread itself gives me a huge output of numbers in the console, wont stop scrolling and will never reach the spectrogram command. The numbers look like this, and it scrolls for years.
-0.0190 -0.0387
-0.0687 -0.4357
-0.0253 -0.1229
0.0561 0.3603
0.1308 0.3627
0.1283 0.1240
0.0004 0.0327
How do I switch it off?
You are probably missing a semicolon.
Does this help?
http://uk.mathworks.com/help/matlab/matlab_prog/symbol-reference.html#bsgigzp-47

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{:})

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!

how to crop image in matlab using only for loop? [duplicate]

This question already has an answer here:
Zoom and Crop Image (Matrix)
(1 answer)
Closed 7 years ago.
i made it with Matrix.how can i make it with for loop
crop.m
function s=crop(f,m,n,x,y)
s=f(x:x+m,y:y+n);
this is code
crop1.m
function s=crop1(f,m,n,x,y)
for i=x:1:x+m
for j=y:1:y+n
s(i-x+1,j-y+1,:)=f(i,j,:);
end
end

How to vectorize a loop in matlab [duplicate]

This question already has answers here:
Structure initialization with repmat
(2 answers)
Closed 9 years ago.
I want to use a function repmat to write this code:
for j=1:30
for i=1:10
myObject{i,j}.s = zeros(6,1);
end
end
I cannot understand how to do that for cells. Can anyone help me please?
You can use deal:
[myObject{1:10,1:30}] = deal( struct('s',zeros(6,1) );
PS: It is best not to use i and j as variables in Matlab.