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

7 次查看(过去 30 天)
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
Stephen23 2021-12-25
编辑: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 个评论
IDN
IDN 2021-12-25
Thanks for getting back i am getting the following error, Unable to perform assignment because the left and right sides have a different number of elements.
IDN
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
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
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."

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by