필터 지우기
필터 지우기

I have a mat-file of 1-by-500001 matrix. I want to create a 1000-by-1000 matrix from it. How to do this?

조회 수: 2 (최근 30일)
The file has number of elements want to use only first 1000 elements???? Help me... Thanx in advance..

답변 (1개)

dpb
dpb 2013년 10월 5일
편집: dpb 2013년 10월 5일
Do you want the first 1000 elements or a 1k X 1k array as the title says? They're not commensurate.
Either way; pick the N that you want and then reshape
Say it's a 1K by 1K...
x=load('yourmatfile');
N=1000; % set the size desired for generality
x=reshape(x(1:N*N),N,N); % keep the N^2 first and reshape to square..
ADDENDUM:
x=load('yourmatfile');
N=1000; % set the size desired for generality
N=min(N,sqrt(length(x)); % modify to make fit if length(x)<N^2
x=reshape(x(1:N*N),N,N); % keep the N^2 first and reshape to square..
That'll fix the overrun error as also noted elsewhere but gets the solution into the Answers section...
  댓글 수: 7
dpb
dpb 2013년 10월 5일
편집: dpb 2013년 10월 5일
Don't send; attach it here.
But, can resolve the problem w/o the actual file -- see ERRATUM: posted above that accounts for actual length of the file instead of presuming the request was reasonable/possible.

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by