How to use indexing to identify data in data(1, :) from points identifed in data(2,:)?

Hi all,
I have a 2x17205 array (called vas_med_env; attached).
in vas_med_env(2,:) I have identified :
j= [5.8150 6.8350 7.8550 8.850]
Now I want to use j, to ''extract' data in vas_med_env(1,:) , by using indexing
my approach below:
n = length(j)-1;
vas_med_cycle = cell(n,1) ;
for i = 1:n
vas_med_cycle{i} = (vas_med_env(1, :),(vas_med_env(2, :),j(i):j(i+1))) ;
end
results in
vas_med_cycle{i} = (vas_med_env(1, :),(vas_med_env(2, :),j(i):j(i+1))) ;
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters.
Can you help please?

 採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 21 日
You have a right-hand side expression of the form
(A, (B, C))
That has no meaning in MATLAB.
MATLAB does not define any way to create "tuples". That expression would not create a tuple in which the first element is A and the second element is a tuple in which the first element is B and the second element is C.
Perhaps you meant
vas_med_cycle{i} = {vas_med_env(1, :), {vas_med_env(2, :),j(i):j(i+1)}} ;
or perhaps you meant
vas_med_cycle{i} = [vas_med_env(1, :), vas_med_env(2, :), j(i):j(i+1)] ;

4 件のコメント

Tomaszzz
Tomaszzz 2022 年 5 月 21 日
Hi @Walter Roberson. Many thanks for the answer and explanation.
What I aim is to produce is a 3x cell with:
cell 1 being: vas_med_env(1, :) between j(1) and j(2)
cell 2 being: vas_med_env(1, :) between j(2) and j(3)
cell 3 being: vas_med_env(1, :) between j(3) and j(4)
with j refering to values in vas_med_env(2, :) ;
neither of the above procudes this, with:
the first line: producing 3x 1 cell including 1x2 cells each including 1x 1705 double
the second line producing 3x 1 cell each including 1x34412 double
j = vas_med_env(2, :);
idx1 = j(1):j(2);
idx2 = j(2):j(3);
idx3 = j(3):j(4);
vas_med_cycle(:,i) = {vas_med_env(1, idx1); vas_med_env(1, idx2); vas_med_env(1,idx3) };
Where does i come into this?
Tomaszzz
Tomaszzz 2022 年 5 月 22 日
This indded does the trick, thanks!
I wonder if you want something closer to
idx1 = j(1):j(2)-1;
idx2 = j(2):j(3)-1;
idx3 = j(3):j(4);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by