Find all values between 2 index columns

Say two columns (C) be this:
1 5
7 13
20 32
These are index values. The 1st column is the starting index, the 2nd column the ending index.
I want to find all values from (dataset) between these 2 index columns.
If i use this code, it only gives me values for the 1st row.
value = dataset(C(:,1):C(:,2));
How do I code this, so that it gives me all the values for every index row?
Many thanks.

 采纳的回答

KSSV
KSSV 2021-3-2
编辑:KSSV 2021-3-2
for i = 1:size(c,1)
value = dataset(C(i,1):C(i,2));
end

5 个评论

Thanks for the answer, although I do get this error when I try it out:
Index in position 2 exceeds array bounds (must not exceed 2).
There was type error...edited the code now...
Yea, it only gives me 1 value.
for ai = 1:size(ddindex,1)
ddvalue = rain(ddindex(ai,1):ddindex(ai,2));
end
Here is my code, just to make sure I'm not doing anything wrong.
To clarify, I've attached the datasets.
Thanks in advance for helping me out.
load index.mat ;
load Rain.mat ;
N = size(ddindex,1) ;
ddvalue = cell(N,1) ;
for ai = 1:size(ddindex,1)
ddvalue{ai} = rain(ddindex(ai,1):ddindex(ai,2));
end

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by