Swap structure values into strings

Finds fields of a structure in a string, and replaces them with the corresponding field values.
196 Downloads
Aktualisiert 22. Nov 2011

Lizenz anzeigen

Searches a string for field names contained in a given structure, then replaces each occurrence of the field name with the corresponding field value.

I use this for dynamically changing the titles on my plots during simulations that require variation of parameters.

Code for title in the image:
% normal use (line 2)
>> q.mu = 0; q.theta = 2; q.sig = 0.3;
>> utitle{2} = struct2strrep(q,'dI_n/dt = q.theta(q.mu-I_n)dt + 2*q.sigW\surddt');

% use with an anonymous function (line 1), useful when both a function and parameter are changing
>> p.A = 1.6; p.f = 50/1000; p.dc = 0;
>> Ia = @(t,p) p.dc + p.A *sin( 2*pi* p.f *t );
>> utitle{1} = struct2strrep(p,['I_a = ' strrep(func2str(Ia),'@(t,p)','') ' mA']);

Zitieren als

Zachary Danziger (2024). Swap structure values into strings (https://www.mathworks.com/matlabcentral/fileexchange/33882-swap-structure-values-into-strings), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2011b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Structures finden Sie in Help Center und MATLAB Answers
Communitys
Mehrere Dateien sind in der  Power Electronics Control Community erhältlich

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0