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

조회 수: 7 (최근 30일)
IDN
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
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에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by