Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I would like to create an axis from the dates 03-01-2014 to 2-28-2015 with (289*12) individual data points. So for each month the X-axis will have the month shown for every 288 data points I have in my array.
Does someone know how I can achieve this?
You can do this by three function which already available in Matlab toolbox
first plot your data(it would be better if you say how we can regenerate your data because of that i try my own )
x = [1 2 3 4 5 6];
data = sin(x);
plot(x,data)
this 3 lines code gave me below plot for instance.
so how we could add month to axis ?! we can do it with set and gca like below
set(gca,'xtick',1:6); % this xtick is very important(i said in this line i want to have x axis ticks in 1,2,3,..,6 so if your x axis is different you must change this line)
set(gca,'xticklabel',{'03-01-2011','03-01-2012','03-01-2013','03-01-2014','03-01-2015','03-01-2016'})
set(gca,'XTickLabelRotation',30)
the output will be
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I loaded in the 1000x1 .txt file but I need to make it 100x10? How do I do this in matlab?
Thanks
Reshape should do this for you. https://www.mathworks.com/help/matlab/ref/reshape.html
But you haven't explained any criteria regarding what the change of dimensions is based on. So, it may not be exactly what you want.
You can use the reshape function to do this. In the example below I created a column vector x that is 1000 x 1 containing numbers that ramp from 1 to 1000. I didn't know what order you wanted the rows and columns populated, so I created variables x2 and x3 with the two variations, you can choose the form that fits your needs.
x = (1:1000)';
% x2 is created with one column at a time
x2 = reshape(x, 100, 10);
% x3 is created one row at a time
x3 = reshape(x, 10, 100)';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am very new to Matlab and coding in general, so I apologize if this is a basic question.
I have a matrix of three columns (data1) where the first column refers to time (s).
I would like to make a new matrix (bout1) consisting of entire rows of the matrix data1 based on the values in the first column (so, for example, in a range from 30 s to 120 s).
I know how to extract the rows based on the row number:
bout1 = data1(361126:391643,:)
but not based on the values in a specific column.
You can use the find function (see here) to find the rows you need, like this:
time = data1(:, 1);
i = find(30 <= time & time <= 120);
bout1 = data1(i, :);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to use geoplot command to show latitude and longitude and change the line color using a third variable speed. Speed is a array of size (120,3). How can I do this considering that I want to represent my data on a map (using geoplot)? The colour and corresponding value can be checked with colourbar.
I am using MATLAB.
Have a look at the documentation of geoplot. Use the name-value pair 'Color','r' to configure red lines in this case (r:red, k:black, b:blue, g:green,... or use a 3x1 RGB array (normalized), see here). You can also use the keyword 'LineStyle' to set e.g. dashed lines.
c = [1 0 0]; % RGB | [255 0 0]/255
geoplot(...,'Color',c);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to pick two different random elements from given array with their positions. Similar like with datasample, but with datasample there is a possibility of picking the same element twice.
I could use while loop or similar, but I suppose there is an easier way to do it.
Say you have a matrix A:n by m, you can choose two elements at random as following,
A=[2 7 8;5 4 6;8 3 11];%given array
[n m]=size(A);
x=2;%two different random elements
i=randperm(n,x)%row index for x elements
j=randperm(m,x)%column index for x elements
A(i(1),j(1)) %First random element
A(i(2),j(2)) %Second random element
If you try this you could get something like,
i =
2 3
j =
2 1
ans =
4
ans =
8
the code can be further simplified but just wanted to make it clear. Please let me know if you have any additional questions or require further clarification.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need to start with the highest value in the matrix (i,j). Then, go backwards to one of positions (i-1,j), (i, j-1), and (i-1, j-1) depending on the direction of movement used to construct the matrix. This method is used throughout until a matrix cell with zero value is reached.The above image shows what I want, I need to trace those marked in blue. I know there is a max function in matlab.
If I understand what you try to do...
Suppose M is your matrix:
result=[];
[~,ind]=max(M(:));
[r,c]=ind2sub(size(M),ind);
result=[result; r c];
while M(r,c)~=0
[~,f]=max([M(r-1,c),M(r,c-1),M(r-1,c-1)]);
switch f
case 1
r=r-1;
case 2
c=c-1;
case 3
r=r-1;
c=c-1;
end
result=[result; r c];
end
Then, result is a 2 x n matrix, where each row is the indexes of one step- from the upper to lower.