How to use Find (or any other function) to create an Array

조회 수: 2 (최근 30일)
Lucinda Nott
Lucinda Nott 2020년 11월 15일
댓글: Lucinda Nott 2020년 11월 17일
Hi Everyone,
I have an array, S that appears as so:
And I want to Find the last place where a 1 occured. However, I essentially want to find the last place for each column (I am unsure of how to describe this)
I want my find to be as so:
Intervals = [1 1 1 1 1
3 2
4 ]
With using the max function I would like to create the array:
Max = [4 1 1 1 2]
The rows represent days and columns represent the replication - so essential I want to find the last day the replication achieved a 1.
Any help would be greatly appreciated even a push in the right direction :)

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 15일
편집: Ameer Hamza 2020년 11월 15일
Try this
S = [
1 1 1 1 1
0 0 0 0 1
1 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0];
[~, idx] = max(flipud(S));
idx = size(S,1)-idx+1;
Result
>> idx
idx =
4 1 1 1 2

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 11월 15일
Here's another possible way
r = repmat((1:9)',1,5); max(r.*S_dash)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by