concatenate matrix with zeros function

if I have matrix a = [2 3 4; 5 6 7; 8 9 1],
zeros = (a, 2)
is this a valid code? because one of my working code has this. if so how does the output look like ?

7 件のコメント

Matt J
Matt J 2022 年 6 月 15 日
if so how does the output look like ?
Can't you tell by running it?
Ashis Pandey
Ashis Pandey 2022 年 6 月 15 日
When I run it shows error, Seems like it doesn’t work, but same thing is happening in my working code and it works
Ashis Pandey
Ashis Pandey 2022 年 6 月 15 日
so why this code doesnt work ?
Ashis Pandey
Ashis Pandey 2022 年 6 月 15 日
編集済み: per isakson 2022 年 6 月 15 日
I am trying to understand why this is supposed to work.. you see second line doesnt make sense (ant_pairs contains a matrix), I also dont know how adding .length makes any difference
ants_pairs = vtrigU.vtrigU.GetAntennaPairs(mySettings.txMode);
TxRxPairs = zeros(ants_pairs.Length,2);
for ii = 1: ants_pairs.Length
TxRxPairs(ii,1) = double(ants_pairs(ii).tx);
TxRxPairs(ii,2) = double(ants_pairs(ii).rx);
end
KSSV
KSSV 2022 年 6 月 15 日
What you want to do? What exactly is your question?
Ashis Pandey
Ashis Pandey 2022 年 6 月 15 日
In short, if I have matrix a = [2 3 4; 5 6 7; 8 9 1],
zeros = (a, 2)
Why this above code don’t work but the below one(see the third line with zeros function in it) works although both are similar?
%Get antenna pairs and convert to matlab matrix
ants_pairs = vtrigU.vtrigU.GetAntennaPairs(mySettings.txMode);
TxRxPairs = zeros(ants_pairs.Length,2);
for ii = 1: ants_pairs.Length
TxRxPairs(ii,1) = double(ants_pairs(ii).tx);
TxRxPairs(ii,2) = double(ants_pairs(ii).rx);
end
per isakson
per isakson 2022 年 6 月 15 日
編集済み: per isakson 2022 年 6 月 15 日
Let me guess. The value of ants_pairs.Length is a scalar. The word, Length, supports that. The value of a is a 2D array. See zeros.
zeros([2,3],4)
Error using zeros
Size inputs must be scalar.

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

回答 (1 件)

Chunru
Chunru 2022 年 6 月 15 日

0 投票

The code "TxRxPairs = zeros(ants_pairs.Length,2)" is correct. It has the function name "zeros" followed by the arguments inside the brackets. The first argument "ants_pairs.Length" is a scalar rather a vector or matrix.
> In short, if I have matrix a = [2 3 4; 5 6 7; 8 9 1],
> zeros = (a, 2)
The statement of "zeros = (a, 2)" is wrong. First, the correct stament should be function name (zeros) followed by arguments inside brackets, say
% x = zeros(a, 2) % wrong
Even the above is still not correct, as a is not a scalar. So the correct statement should be
a = [2 3 4; 5 6 7; 8 9 1];
x = zeros(size(a)) % where size(a0 = [3 3]
x = 3×3
0 0 0 0 0 0 0 0 0
The above is correct in syntax. But we don't know if it is what you want.
You can also have:
y = zeros(a(1,1), 2) % where a(1,1) is a scalar
y = 2×2
0 0 0 0

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 6 月 15 日

編集済み:

2022 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by