Indexing concatenated matricies without changing the order

조회 수: 1 (최근 30일)
Elia . 2014년 10월 30일
댓글: Abhiram Bhanuprakash . 2014년 10월 31일
I'm attempting to index an outputted matricy from one function into a bigger matricy. My code at the moment:
% code
while j <= length(sec)
maxbox = [maxbox;max];
The output max finds the largest values in a data set and outputs it as a matricy [x y]. Sample output:
if true
3 10
5 12
9 15
I then use maxbox = [maxbox;max]; to concatenate the matricies. I'd like to have each output correspond to the value of j it was found at. So that I know when they occur as well as where they occur. (j being time).
Sample of desired output:
if true
j 3 10
j 5 12
j 9 15
Before I concatenate it with the next matricy of values at j+1. Help is appreciated! Thanks.

채택된 답변

Abhiram Bhanuprakash
Abhiram Bhanuprakash 2014년 10월 30일
Hi Elia,
I guess you can use the 'ones' and 'size' functions to do this.
In your case, inside the 'while' loop, you can do:
maxbox = [maxbox;max];
temp = j*ones(size(maxbox,1),1);
maxbox = [temp maxbox];
j = j+1;
For documentation on 'ones' and 'size' functions, you can refer:
- ones: here
- size: here
Hope this helps,
  댓글 수: 3
Abhiram Bhanuprakash
Abhiram Bhanuprakash 2014년 10월 31일
Thanks Elia and Image Analyst!

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

추가 답변 (0개)


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

Community Treasure Hunt

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

Start Hunting!

Translated by