Error using save, too many output arguments - don’t know how to fix.
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hi y’all
I am trying to save multiple tables I’ve edited in matlab, but I get this error:
Error using save
Too many output arguments.
I’m having trouble figuring out how to fix this. The code it’s probably referring to is:
 function [output] = save_on_Computer(ReferenceData, month, day) 
    file_name     = "OL_"+month+"_"+day+".csv" ; 
    savefile      = save(file_name) ; 
    output        = savefile ; 
 endfrom the full code here:
 % Pull data from files 
 function [output]   = each_day_table(month, day)
   fileNames        = sprintf('D2024%02d%02d*.csv', month, day) ;
   datastore_result = datastore(fileNames) ;
   original_data    = readall(datastore_result) ;
   output           = original_data ;
 end % Find Where Equivilant Diamiter > 150 And Remove (ICB measures b/w 2 - 150 μm)
 function [output] = remove_150(original)
    new = original ;
    Greater150 = original.EquivDiameter > 150 ;
    new(Greater150, :) = [] ; 
    output = new ;
 end % To Save Each Newly Made File Onto Computer 
 function [output] = save_on_Computer(ReferenceData, month, day) 
    file_name = "OL_"+month+"_"+day+".csv" ; 
    savefile = save(file_name) ; 
    output = savefile ; 
 end function [output] = do_everything(year, month, day) 
    original_data = each_day_table(month, day) ; 
    data_lessthan_150 = remove_150( original_data) ;
    save_to_folder = save_on_Computer(data_without_zeroes, month, day) ; 
    output = save_on_Computer ; % change data_with_surface_area with data_with_ratio
 endOL_06_03 = do_everything (2024,06,03) ; OL_06_04 = do_everything (2024,06,04) ; OL_06_05 = do_everything (2024,06,05) ; OL_06_06 = do_everything (2024,06,06) ;
0 Commenti
Risposta accettata
  dpb
      
      
 il 23 Mar 2025
        
      Modificato: dpb
      
      
 il 24 Mar 2025
  
      Indeed, the problem is in
function [output] = save_on_Computer(ReferenceData, month, day) 
    file_name     = "OL_"+month+"_"+day+".csv" ; 
    savefile      = save(file_name) ; 
    output        = savefile ; 
end
The <save> function doesn't return any output; it just writes the requested data to file...if you want the returned save'ed filename, then just
function file_name = save_on_Computer(ReferenceData, month, day)
% saves present 
  file_name = "OL_"+month+"_"+day+".csv";
  save(file_name)
end
is all you need/want, although I'd note the above doesn't provide any opportunity to set an output target folder other than whatever is the <pwd> at the time the function is called. 
It also will not write a csv file despite the name; instead it will save all of the local variables in scope (|ReferenceData|, month, day, and file_name) as variables in a .mat file with the given name.
One presumes your real intent is to write only the ReferenceData and those as a .csv file; that actually cannot be done by save; it can write a tab-delimited text file, but not comma-separated, and it also requires that the data be a vector or 2D array at most (no structs, tables, etc.).
If that's good enough, then
function file_name = save_on_Computer(ReferenceData, month, day)
% saves present 
  file_name = "OL_"+month+"_"+day+".txt";
  save(file_name,'ReferenceData','-ascii','-double','-tabs')  % 16 digits, '-single' --> 8 digits
end
function file_name = save_on_Computer(ReferenceData, month, day)
% saves present 
  file_name = "OL_"+month+"_"+day+".csv";
  writematrix(ReferenceData,file_name)  % writematrix will use file extension and write comma-delimited
end
Again, you're limited to arrays and if pass an array of more than 2D, then the trailing dimensions are collapsed.
10 Commenti
  Walter Roberson
      
      
 il 25 Mar 2025
				I can certainly see how a general non-programmer user could interpret that as "returning" the file name...
I personally do not see how anyone reasonable could interpret menu saving commands as "returning" file names in a way that could be assigned to variables.
Più risposte (2)
  Steven Lord
    
      
 il 23 Mar 2025
        None of the syntaxes listed in the Syntax section of the documentation page of the save function indicate it returns any output. If you tell us what you were hoping that variable would contain we may be able to tell you how to create that variable.
0 Commenti
  Walter Roberson
      
      
 il 23 Mar 2025
        save() does not support any output arguments.
You also have the problem that save() with a single input argument will save all of the variables in scope -- including ReferenceData, month, day and file_name 
 function [output] = save_on_Computer(ReferenceData, month, day) 
    file_name     = "OL_"+month+"_"+day+".csv" ; 
    save(file_name, 'ReferenceData'); 
    output        = file_name ; 
 end
0 Commenti
Vedere anche
Categorie
				Scopri di più su Environment and Settings in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




