Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Conditional split into columns

조회 수: 3 (최근 30일)
fatduck9
fatduck9 2017년 10월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi all, I have got this array A=[10 20 30 40 50 10 20 30 40 10 30 30 40 .. .. Val]
My goal is to create a new column once an element of value 10 occurs in the array. Then I want to make a maximum of each particular column.
10 10 10
20 20 ..
30 30 ..
40 40
50
[50] [40] [..]
I tried some built in function within a loop (like sum, reshape, splitarray etc.) but there has always been an error which I did not understand quite much. Would anybody give me a hint, please?
Thank you.
  댓글 수: 1
Stephen23
Stephen23 2017년 10월 30일
All elements of an array/matrix must contain a value. What value do you put into the second row third column position?

답변 (2개)

Rik
Rik 2017년 10월 30일
You might be able to bodge this together with a conversion to char, use strsplit (or even textscan), and use cellfun to convert back to double and find the max.

KL
KL 2017년 10월 30일
편집: KL 2017년 10월 30일
You could use a cell array,
A=[10 20 30 40 50 10 20 30 40 10 30 30 10 20 10 10 20 30];
inds = find(A==10);
res = arrayfun(@(x,y) A(x:y-1),inds,[inds(2:end) numel(A)+1],'uni',0)
and then to find the maximum,
maxRes = cellfun(@max,res)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by