Effacer les filtres
Effacer les filtres

Indexing concatenated matricies without changing the order

1 vue (au cours des 30 derniers jours)
Elia
Elia le 30 Oct 2014
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)
y=sec(j,:);
[max,~]=coros(y,thershold,x);
maxbox = [maxbox;max];
j=j+1;
end
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
end
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
end
Before I concatenate it with the next matricy of values at j+1. Help is appreciated! Thanks.

Réponse acceptée

Abhiram Bhanuprakash
Abhiram Bhanuprakash le 30 Oct 2014
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;
end
For documentation on 'ones' and 'size' functions, you can refer:
- ones: here
- size: here
Hope this helps,
Cheers!
Abhiram
  3 commentaires
Image Analyst
Image Analyst le 30 Oct 2014
Please go ahead and give him "credit" by officially marking the answer as "Accepted". Then read this so you'll know how to format your posting properly.
Abhiram Bhanuprakash
Abhiram Bhanuprakash le 31 Oct 2014
Thanks Elia and Image Analyst!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by