MATLAB How Can I Simplify This Matlab Source Code for GUI Implementation?

AI Thread Summary
The discussion revolves around simplifying a Matlab code snippet for use in a GUI, specifically focusing on dynamically accessing elements from a matrix called "gains". The user seeks to automate the assignment of the variable "kn" based on a user-defined input "n". The suggestion made is to restructure the code so that "kn" can be directly assigned using the syntax "kn = gains(k, n)" within an outer loop. This approach aims to streamline the code and enhance its functionality for GUI integration. The overall goal is to improve the code's efficiency and adaptability to user inputs.
fsven
Messages
1
Reaction score
0
Hi, Matlab noob here.

I need your help to simplify this Matlab source code. Here the code that i currently use

for k=1:1:gg
k1=gains(k,1);
k2=gains(k,2);
k3=gains(k,3);
.
.
kn=pidgains(k,n)


[T,X,Y]=sim('Evaporator_PID',[Tstart Tfinal],opt);

end​

The code above need to implement into GUI and the "n" is a value that assign by user. So i need to create a code that can generate the "kn=gains(k,n);" automatically.
"gains" is matrix like "54xn".

Thanks in advance.
 
Physics news on Phys.org
it would probably be easiest to make your gains an arrray such that
k(n) = gains(k,n)

and place that in an outer loop
 
Back
Top