Calling a function and saving all the data in same matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Darpan Verma
el 30 de Nov. de 2019
Comentada: Darpan Verma
el 30 de Nov. de 2019
% This is Main code to call the function
% The function is function[SimData, A_Val, BB_Val] = MM_BG_FuncCall(A,BB)
BG = 3.42:0.05:3.52;
B_B = linspace(0.9,1.1,2);
for j = 1:length(BG)
for k = 1:length(B_B)
[alpha, A_Val, BB_Val] = MM_BG_FuncCall(BG(j),B_B(k));
end
end
clear B_B
clear BG
clear j
clear k
I am trying to call a function and function is calculating alpha value and every time it is called its giving a [1x79] Matrix, similarly, Everytime the B_B and BG value is changing the function is called and giving out the values, when I try to save the function in the three variables [alpha, A_Val, BB_Val], I am only getting the final (last) result, Though I want alpha to be updated for example first row of alpha should have all [1x79] values, second row should have next [1x79] values and so on for the other two variables A_Val and BB_Val as well. Could any one tell me how can I save all the data that's the called function is calculating?
Thank You in advance
![Screen Shot 2019-11-30 at 3.11.51 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251636/Screen%20Shot%202019-11-30%20at%203.11.51%20PM.png)
0 comentarios
Respuesta aceptada
KALYAN ACHARJYA
el 30 de Nov. de 2019
Editada: KALYAN ACHARJYA
el 30 de Nov. de 2019
when I try to save the function in the three variables [alpha, A_Val, BB_Val], I am only getting the final (last) result, Though I want alpha to be updated for example first row of alpha should have all [1x79] values
Yes because, each iteration it replaces the previous data. To save the each iteration data, you can save the those output arguments variables in array or cell array depending on its types.
for j = 1:length(BG)
for k = 1:length(B_B)
[alpha, A_Val, BB_Val]= MM_BG_FuncCall(BG(j),B_B(k));
alpha_data{k}=alpha;
% Same for others, if A_Val is vector then A_Val{k}=..., BB_Val{k}=...,
% if scalar, then A_Val(k)=... BB_Val(k)=...
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!