Replication factors must be a row vector of integers or integer scalars.

15 ビュー (過去 30 日間)
Skydriver
Skydriver 2019 年 6 月 13 日
回答済み: Steven Lord 2019 年 6 月 13 日
My coding is
depth = [0.01 1.5:1.5:30]';
w = 10 - 0.5 .* depth;
w(w<0) = 0;
a=829862;
b=21
c=a/b
W = repmat(w,c,1);
The result is replication factors must be a row vector of integers or integers scalars
Does any one can help me?

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 6 月 13 日
c must be an integer. Then, a solution:
depth = [0.01 1.5:1.5:30]';
w = 10 - 0.5 .* depth;
w(w<0) = 0;
a=829862;
b=21
c=round(a/b)
W = repmat(w,c,1);
  2 件のコメント
Skydriver
Skydriver 2019 年 6 月 13 日
Thank you it works know
Alex Mcaulley
Alex Mcaulley 2019 年 6 月 13 日
Then, accept the answer to close the question please

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 6 月 13 日
If you want to replicate w so it has exactly a elements, I recommend doing two things. Let's operate on some very simple sample data.
w = 1:21;
While I would call your a variable something like desiredLength to make its purpose obvious, I'll use your variable name for this example. Similarly I would call b something like wLen.
a = 829862;
b = length(w);
The length function is good if you know its input is a vector. If you're not sure and need to know how many elements the input has use numel instead.
Using the ceil function ensures that b*multiplesNeeded is at least a. This means when replicatedW is created on the second line below it has at least a elements. Then the third line trims the excess elements (no more than b-1.)
multiplesNeeded = ceil(a/b);
replicatedW = repmat(w, 1, multiplesNeeded);
replicatedW(a+1:end) = [];

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by