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

4 visualizaciones (últimos 30 días)
IDN
IDN el 25 de Dic. de 2021
Comentada: IDN el 25 de Dic. de 2021
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!

Respuestas (2)

Stephen23
Stephen23 el 25 de Dic. de 2021
Editada: Stephen23 el 25 de Dic. de 2021
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 comentarios
IDN
IDN el 25 de Dic. de 2021
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 el 25 de Dic. de 2021
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?

Iniciar sesión para comentar.


Jan
Jan el 25 de Dic. de 2021
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 comentario
IDN
IDN el 25 de Dic. de 2021
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."

Iniciar sesión para comentar.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by