How to remove values from a data set to make it a specific length?

4 ビュー (過去 30 日間)
Alfredo Scigliani
Alfredo Scigliani 2022 年 4 月 20 日
コメント済み: Dyuman Joshi 2023 年 10 月 30 日
I will explain myself better:
If I have
xdata = [ 1 2 3 4 5 6 7 8 ]
ydata = [ 1 2 3 4 5 6 ]
if I want to plot(xdata,ydata) it will say that the vectors must be the same length and I cannot plot it. Instead of going to my specific data set and manually deleting values, I would like xdata to have the same length as ydata. Somehow deleting those values, making them = [ ], so that both of them have the same length.
  3 件のコメント
Voss
Voss 2023 年 10 月 30 日
xdata = [ 1 2 3 4 5 6 7 8 ];
ydata = [ 1 2 3 4 5 6 ];
% n is the minimum of {number of elements in xdata, number of elements in ydata}
n = min(numel(xdata),numel(ydata));
xdata_new = xdata(1:n);
ydata_new = ydata(1:n);
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 30 日
@Suuz Schouten, if you go through Voss's answer below, you will find the logic (and implementation as well) for that.

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

採用された回答

Voss
Voss 2022 年 4 月 20 日
If that's what you want to do
xdata = [ 1 2 3 4 5 6 7 8 ];
ydata = [ 1 2 3 4 5 6 ];
% n is the minimum of {number of elements in xdata, number of elements in ydata}
n = min(numel(xdata),numel(ydata));
% plot the first n elements of ydata vs the first n elements of xdata
plot(xdata(1:n),ydata(1:n))

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by