Hi, I'm trying to perform the following code but I keep getting an error using save. The code is supposed to load the filename and data for .txt files in a specified folder and shuffle the data from each .txt file using a SmallShuffle function to create the variable SS_data. It's then supposed to save multiple output files (18 copies plus the original filename copy) where each file contains one single column of shuffled data. The output files are supposed to be saved as the original filename plus the copy number…(ie. if the original file was called myfile.txt the output files should be myfile1.txt, myfile2.txt,…., myfile18.txt). Right now the non-command format works, but it only gives a single output file titled "outputfile". I have also tried using the command format: save (outputfile ,'SS_data','-ascii'); but it gives me an error "must be a string scalar or character vector". How could I resolve the output title problem and errors associated with save?
directory_name = uigetdir(pwd,'Select data directory');directory_name = ([directory_name '/']);files = dir([directory_name,'*txt']);if isempty(files) msgbox('No raw files in this directory')endFileName=[];for i=1:length(files) for j=1:18 filename=files(i).name; data = load(filename,'-ascii'); filename=filename(1:end-4); FileName=[FileName; cellstr(filename)]; outputfile = strcat(FileName,num2str(j),'.txt'); A=1; SS_data=SmallShuffle(data,A); save outputfile SS_data -ascii; end end
Best Answer