# Passing multiple Arrays to loop a Function and creating a 1 column array

8 ビュー (過去 30 日間)
IDN 2021 年 12 月 25 日
コメント済み: IDN 2021 年 12 月 25 日
Hello! I have the following but I am not sure what i am missing:
A=ArrayA; (1,000x1) Double
C=ArrayC; (1,000x1) Double
V=ArrayV; (1,000x1) Double
sz = 1000
mmm = zeros(size(sz));
for i = 1:sz
sh(A,C,V) = Function(HistoricalValue,A,C,C,V,V);
mmm(i,:) = sh;
end
What i am trying to do is pass a list of values A,C,V thru my function so its evaluated unders those passing values and store the result in "mmm" thru a loop.
Would appreciate any help! Thanks!

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

### 回答 (2 件)

Stephen23 2021 年 12 月 25 日

Assuming that the function output is scalar:
mmm = zeros(sz,1);
for k = 1:sz
mmm(k) = Function(HistoricalValue,A(k),C(k),C(k),V(k),V(k));
end
##### 2 件のコメント表示非表示 1 件の古いコメント
IDN 2021 年 12 月 25 日
So when the function evaluates
mmm(k) = Function(HistoricalValue,A(k),C(k),C(k),V(k),V(k));
HistoricalValue is a list of 4,252 values
C,V,K are arguments/coeffcientes that derive and answer to the equation
Therefore, I am looking to to pass this list of 1,000 arguments to get 1,000 answers as the function runs and provides an answer. Maybe thats causing the difference left and right sides?

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

Jan 2021 年 12 月 25 日
The code contains some strange details:
A = ArrayA; (1,000x1) Double
Please use the standard notation. I assume this would be some matching test data:
A = rand(1000, 1);
sz = 1000;
mmm = zeros(size(sz));
sz is a scalar. Then size(sz) is [1,1]. I guess, that mm should not be a scalar. Maybe you want:
mm = zeros(sz, 1);
It would be useful to mention the size of the output of "Function".
I cannot imagine, why the inputs C and V are provided twice. Is this typo?
With some bold guessing:
mm = zeros(sz, 1);
for k = 1:sz
mmm(k) = Function(HistoricalValue, A(k), C(k), V(k));
end
##### 1 件のコメント表示非表示 なし
IDN 2021 年 12 月 25 日
Thanks for the help! This function is looking at ranges of values (min/max), alternarively if i dont want to apply a range then in my input i can provide the value twice which is what i am doing there so its no typo. Getting this error "Unable to perform assignment because the left and right sides have a different number of elements."

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

R2020a

### Community Treasure Hunt

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

Start Hunting!