0

次のコードがある場合:

for t=1:length(s)  % s is a struct with over 1000 entries
  if s(t).BOX==0
    a(t,:)=0;
    elseif s(t).BOX==1
    a(t,:)=100;
  end
  if s(t).BOX==2
    b(t,:)=150;
    elseif s(t).BOX==3
    b(t,:)=170;
  end
  .
  .
  .

end
plot(a)
plot(b)
plot(c)

私が達成したいこと:

for n=1:length(s)

Plot the data point of a(n) at t=0, t=1, t=2
then
Plot the data point of b(n) at t=3, t=4, t=5
.
.
.
etc

したがって、基本的に、各データ ポイントはt、次のポイントに移動する前に の 3 つの値でプロットされます。

どうすればそれを達成できますか?

編集

このようなもの :

ここに画像の説明を入力

4

1 に答える 1

1

私があなたを正しく理解してaいて、 がベクトルであると仮定すると、次のようなことができます

% Your for loop comes before this

nVarsToPlot = 4;
nRepeatsPerPoint = 3;
t = repmat(linspace(1, nRepeatsPerPoint * length(s), nRepeatsPerPoint * length(s))', 1, nVarsToPlot);
genMat = @(x)repmat(x(:)', nRepeatsPerPoint, 1);
aMat = genMat(a); bMat = genMat(b); cMat = genMat(c); dMat = genMat(d);
abcPlot = [aMat(:) bMat(:) cMat(:) dMat(:)];
plot(t, abcPlot);

正確にどの値を含めたいかは少しわかりませんtが、基本的に の 3 倍の長さのベクトルが必要ですs[Nx1]次に、ベクトル ( a, b, c, etc.) を 3 回 (行ベクトルに転置した後) それぞれコピーし、ロット全体を行列に積み上げてから(:)、正しい順序で出力されるベクトルに変換することで、正しいデータ行列を生成できます。マトリックスが正しく構築されているためです。

于 2013-04-06T16:34:54.050 に答える