Info

この質問は閉じられています。 編集または回答するには再度開いてください。

error in creating a vector the spans the length of another vector

1 回表示 (過去 30 日間)
scobug411
scobug411 2020 年 9 月 24 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
i am trying to make vector that ranges from 0 to 7/a for each value of a and contains 20 evenly spaced values.
a is a 1x5 vector
ive tried using linspace (Var=linspace(0,7/a,20))and the colon operator (Var=1:20:7/a) but using each, i get the following error message:
Error using /
Matrix dimensions must agree.
should i use a for loop?

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 9 月 24 日
Each row of M corresponds to one value in a
a = [1 2 3 4 5];
M = arrayfun(@(x) linspace(0, 7/x, 20), a, 'uni', 0);
M = vertcat(M{:});

Community Treasure Hunt

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

Start Hunting!

Translated by