How di I make concise multiple parameter calls?
    1 Ansicht (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Brantosaurus
 am 30 Sep. 2022
  
    
    
    
    
    Kommentiert: Brantosaurus
 am 30 Sep. 2022
            Is there an easy way of wrapping up multiple parameter calls via a single entity?
The parameters are a mix of floating point, integer and characters. I have:
formatspec=['\nExit conditions\n',...
            '---------------\n',...
            'Total products:            %d\n',...
            'Maximum fraction:    %f\n',...
            'Species:       	        %d\n',...
            'Product:                   %s\n',...
            'Pressure [bar]:            %f\n',...
            'Ratio:                        %f\n\n'];
fprintf(formatspec,nproducts,mfrac,species,name,pcx,ofx);
I would like something on the lines of:
params=???nproducts,mfrac,species,name,pcx,ofx???;
fprintf(formatspec,params);
3 Kommentare
Akzeptierte Antwort
  Karim
      
 am 30 Sep. 2022
        One way to do this is by storing the data (or params as you call them) in a cell array, see below for an example.
MyString = ['\nExit conditions\n',...
            '---------------\n',...
            'Total products:      %d\n',...
            'Maximum fraction:    %f\n',...
            'Species:             %d\n',...
            'Product:             %s\n',...
            'Pressure [bar]:      %f\n',...
            'Ratio:               %f\n\n'];
% store the params in a cell array
MyParams = {int32(3), pi, 10, "blabla", rand(1)*10, rand(1)}
% print the data
fprintf(MyString,MyParams{:})
Weitere Antworten (0)
Communitys
Weitere Antworten in ThingSpeak Community
Siehe auch
Kategorien
				Mehr zu Prepare and Analyze Data finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!