what is wrong with my code? vertcat error

22 ビュー (過去 30 日間)
EEEmatlab
EEEmatlab 2017 年 10 月 30 日
コメント済み: DGM 2024 年 4 月 6 日
t = [0:0.4:40];
a = [20.*sin(t); 20.*cos(t); 0];
b = [0; 0; (10-((t.^2)/16))];
s = a+b
It gives me: Error using vertcat Dimensions of matrices being concatenated are not consistent. what is wrong?
  1 件のコメント
Stephen23
Stephen23 2017 年 10 月 30 日
編集済み: Stephen23 2017 年 10 月 30 日
You are trying to concatenate vectors with different numbers of columns:
>> size(t)
ans =
1 101
>> size(0)
ans =
1 1
t has 101 columns (as do sin and cos outputs too), whereas 0 has one column. It is not possible to vertically concatenate arrays with different numbers of columns.

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

回答 (3 件)

M
M 2017 年 10 月 30 日
You are trying to define a matrix that can not exist.
In your case, t is a vector of dimension 101
size(t)
ans =
1 101
and so is
20.*sin(t)
but when you write
a = [20.*sin(t); 20.*cos(t); 0];
0 is a scalar of dimension
What you should do is have a look at the function
zeros(M,N) or zeros([M,N]) is an M-by-N matrix of zeros.

Rik
Rik 2017 年 10 月 30 日
The dimensions of matrices being concatenated are not consistent. t is a row-vector, 0 is not.
Apart from that, a will have 203 elements, while b will have only 103 elements, so a+b will fail.

Puneet
Puneet 2024 年 4 月 6 日
A_trans = (T * [A; 1])';
Error using vertcat
  1 件のコメント
DGM
DGM 2024 年 4 月 6 日
You're trying to concatenate an array A, and the scalar 1. A has more than one column.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by