how to split matrix by percentage
Mostrar comentarios más antiguos
I have a matrix R(u,v) and i want to split into 2 new matrices M, N. M will be the first 10% of the rows of R and N will be the rest 90% of the rows
2 comentarios
babis
el 3 de Dic. de 2013
Image Analyst
el 3 de Dic. de 2013
That's what I said, except that my code was robust and correct while yours was not. What if end*0.1 is a fractional number? It will fail whereas I cast to integer so my code won't fail. My code gives N and M like you asked for whereas yours doesn't, and yours doesn't give the final 90% where if you do b(end*.1:end) you'll run into the same problem of fractional indexes. I'd recommend you use my more robust code.
Respuestas (2)
Image Analyst
el 3 de Dic. de 2013
Try this:
% Create some sample data 100 rows by 101 columns.
R = rand(100, 11);
% Determine how many rows 10% is.
[rows, columns] = size(R);
% Determine the last row number of the top (upper) 10% of rows.
lastRow = int32(floor(0.1 * rows));
% Get first 10% into one array M:
M = R(1:lastRow, :);
% Get the rest into one array N:
N = R(lastRow+1:end, :);
9 comentarios
Cappriece Clarke
el 16 de Jun. de 2021
Hi,
To aid my understanding, shouldn't there be a value of 10% in the second line below? When I ran it as is, it gave me the total number of rows in the dataset.
% Determine how many rows 10% is.
[rows, columns] = size(R);
Image Analyst
el 17 de Jun. de 2021
@Cappriece Clarke, to know how many rows 10% of the total number of rows is, you first must determine the total number of rows. This is precisely what
[rows, columns] = size(R);
does. Now once you have rows, you can get 10% of it from 0.1 * rows. Then I round down to the nearest integer since you can't have a fractional row. So I do
% Determine the last row number of the top (upper) 10% of rows.
lastRow = int32(floor(0.1 * rows));
and this does what it says. It gives you the last row number of the upper 10% of rows. So if you have 1009 rows, 10% of that is 100.9. Since you can't have 0.9 of a row, I round down from 100.9 to 100.
Cappriece Clarke
el 18 de Jun. de 2021
@Image Analyst, Thank you so much! I fully understand now.
As a follow up, how do I then determine the threshold value for each array (arrays M and N)?
I am currently working on a research paper that looks at the asymmetric exchange pass-through to prices in my country. The threshold value that I have found is said to be near the lower bound, ergo a recommendation was made to trim the data to the first 10% of the data and then establish the threshold for each groups (the 10% and the 90%). I tried using the code: options.trim=10; to no avail.
Can you kindly assist me in establilshing a code to determine the threshold for the entire data set and for each arrays?
Thank you in advance.
Image Analyst
el 18 de Jun. de 2021
Not sure what your options structure is, but you might want to sort your data first. Sounds like they might be talking about the value distribution (the histogram).
Cappriece Clarke
el 22 de Jun. de 2021
Thank you for your quick response.
Okay. So once I have created the histogram what would be the next move and is there a way to obtain the threshold value for the two arrays?
Image Analyst
el 22 de Jun. de 2021
I have no idea how to segment your histograms into two classes (values you're interested in, like foreground, and values you're not interested in, like background). It totally depends on the signal and what you want. If it's an image, maybe you can try imbinarize(). Or just pick some value, like
indexes = signal > someThreshold;
Cappriece Clarke
el 5 de Jul. de 2021
Hi Image Analyst,
I would like to test the maximum likelihood (mle) function on the parameters of a vector in a loop, to see if each parameter is significant. I would also like to run the wald test on each parameter, could you kindly assist me with this please? Thanks in advance.
The vector is called Colvect.
Image Analyst
el 5 de Jul. de 2021
Not sure I could help. You can try pca to find out how much of the variation is explained by each PC. I think there is also a stepwise regression in MATLAB but I don't know the details. I suggest you explain it thoroughly in a new question, not here in @babis's 8 year old question. Explain it well and attach your data and code and someone may be familiar with the process you should use.
Cappriece Clarke
el 7 de Jul. de 2021
Good day, I totally understand. Thank you.
Azzi Abdelmalek
el 2 de Dic. de 2013
Editada: Azzi Abdelmalek
el 2 de Dic. de 2013
%----Example-------
n=randi(100);
m=10;
R=rand(n,m)
%---------------------
n1=ceil(0.1*n)
Categorías
Más información sobre Linear Predictive Coding en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!