필터 지우기
필터 지우기

set intervals with starts and ends in two arrays

조회 수: 5 (최근 30일)
gabriele fadanelli
gabriele fadanelli 2021년 4월 20일
편집: Matt J 2021년 4월 20일
I know this should be quite an easy answer, but I cannot find the solution: I have two arrays one marks the beginning of the intervals the other sets the ends. so:
starts = [ 1 20 30 40];
ends = [3 22 34 41];
with the ends always ending before the next start. I would like to get an array intervals which should appear either:
intervals = [1 2 3 20 21 22 30 31 32 33 34 40 41];
or:
intervals = [1 2 3; 20 21 22; 30 31 32 33 34; 40 41];
this sounds so dumb to me that I cannot find a way...anyway, I hope somebody can easily help me thanks.
Also, I need to AVOID FOR CYCLES TO DO IT.
  댓글 수: 3
gabriele fadanelli
gabriele fadanelli 2021년 4월 20일
I don't really know, but the solution to the problem should be given without using a for cycle, it is mandatory, not my fault.
gabriele fadanelli
gabriele fadanelli 2021년 4월 20일
I thought it was easy to do it with
starts : ends
or
starts':ends'
but none of them works

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

답변 (1개)

Matt J
Matt J 2021년 4월 20일
편집: Matt J 2021년 4월 20일
Because it's homework, I've left some blanks for you to fill in.
starts = [ 1 20 30 40];
ends = [3 22 34 41];
D=ends-starts;
M=______;
N=numel(starts);
e=(0:M).';
map=______
map = 5×4 logical array
1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 1 0
result=double(map).*e(:)+starts;
result(map).'
ans = 1×13
1 2 3 20 21 22 30 31 32 33 34 40 41

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by