Borrar filtros
Borrar filtros

Extracting two-dimensional data matrix from .csv into individual variables

16 visualizaciones (últimos 30 días)
Hello,
I am fairly new to coding my own Matlab scripts and I am struggling a bit. I have several two-dimensional data arrays that are 1000x256 points each, each done in triplicate, that I need to analyze; they are set up like the attached screenshot.
There is a time compenent and a wavelength component. I need to analyze each as a function of the other. So I need individual variables (or waves) for each wavelength as a function of time, and individual variables for all wavelengths at each time point. Ideally, I'd love to generate .txt files of each variable that I can easily upload into my data manipulation software.
I have looked into several of the functions on the Matlab help pages, but I'm not sure which will be the most useful for this task as I effectively need to generate 1256 files for each data set. The other issue is the data output .csv files have several lines of useless information and data, so it is not just the data to be analyzed, so I need to be able to select just the data cells in the file. This may be a very simple function to do this, I am just stuck and can't seem to find what I am looking for to achieve this result.
Any input or help would be greatly appreciated!
Screen Shot 2019-03-07 at 10.55.33 AM.png

Respuestas (1)

Bob Thompson
Bob Thompson el 8 de Mzo. de 2019
I'm not sure I entirely understand what you're trying to accomplish so I'm going to break things down. Feel free to let me know if I interpreted something incorrectly.
As I understand it, you have several .csv files which contain some header lines and a 1000x256 array of data. Loading this into matlab is fairly simple, just use the csvread command.
datain = csvread('Myfile_1.csv',n); % n represents number of header lines
Because you have several files I would suggest putting this into a loop to read all the files with 'one' command line, just remember to index. It is possible to change the name of you input file reactively either by creating a string, or by looping through a list of files.
filename = ['Myfile_',num2str(i),'.csv']; % Where i is an index to represent file numbers
% or
fildir = dir('*.csv'); % Find .csv files in current folder
datain = csvread(fildir(i).name,n); % Again inside a loop
I don't understand exactly how you're trying to organize the data, but it should all be loaded into matlab now, so you can manipulate it as you need.
For writing files back into ascii you have several options. You can always just print the data back into a .csv file, or you can use dlmwrite, or fprintf for a more classic method.
csvwrite('Myfileout_1.csv',dataout(i));
dlmwrite('Myfileout_1.dat',dataout(i),'');
% or
fid = fopen('Myfileout_1.dat','w');
fprintf(fid,'%s',dataout(i));

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by