필터 지우기
필터 지우기

how to split matrix by percentage

조회 수: 10 (최근 30일)
babis
babis 2013년 12월 2일
댓글: Cappriece Clarke 2021년 7월 7일
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
babis
babis 2013년 12월 3일
thanks for the answers. you helped a lot. I tried this:
a = x(1:end*0.1, 1:end);
b = x(end*0.1:end, 1:end);
c = x(1:end, 1:end*0.1);
d = x(1:end, end*0.1:end);
it seems that it works well.
Image Analyst
Image Analyst 2013년 12월 3일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2013년 12월 3일
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
Image Analyst
Image Analyst 2021년 7월 5일
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
Cappriece Clarke 2021년 7월 7일
Good day, I totally understand. Thank you.

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 2일
편집: Azzi Abdelmalek 2013년 12월 2일
%----Example-------
n=randi(100);
m=10;
R=rand(n,m)
%---------------------
n1=ceil(0.1*n)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by