要素数が変わる変数を​1つの配列にまとめて​後から参照するには

11 visualizaciones (últimos 30 días)
don
don el 18 de Oct. de 2023
Comentada: don el 18 de Oct. de 2023
同じ変数で秒数ごとに値の要素数が変わる変数を作成しました。それを後から秒数を指定して、その秒数の要素をグラフ化したいです。
(例データ)
一秒目に出るデータ
xpos = 10,20,30,40,50
二秒目に出るデータ
xpos = 3,90,2
三秒目に出るデータ
xpos = 40,30,30,20,2,30,44,2,20,6,70
xposの配列(posX[ ] )を作成して都度保存し、posX[i]のi部分に秒数を指定するとその時のデータが取得出来るようにしたいのですが、同じ変数で秒数ごとに値の要素数が変わるので、うまくposX[i]に値を入れられません。対応策を教えていただきたいです。
(例データ)
posX[1] = 10,20,30,40,50
posX[2] = 3,90,2
posX[3] = 40,30,30,20,2,30,44,2,20,6,70

Respuestas (1)

Akira Agata
Akira Agata el 18 de Oct. de 2023
以下のように、 cell 配列を使うと可能です。
% カラのcell配列を作成
posX = cell(3,1);
% 要素数の異なる配列を順に入れる
posX{1} = [10,20,30,40,50];
posX{2} = [3,90,2];
posX{3} = [40,30,30,20,2,30,44,2,20,6,70];
% 確認
disp(posX)
{[ 10 20 30 40 50]} {[ 3 90 2]} {[40 30 30 20 2 30 44 2 20 6 70]}
  1 comentario
don
don el 18 de Oct. de 2023
cell関数を使って配列に格納することができました。
助けてくれてありがとうございます!

Iniciar sesión para comentar.

Categorías

Más información sobre Direct Search en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!