MATLAB: Convert .csv file to .mat file conversionconvertcsvmat I have a csv file of 2 colunms and want to be saved as a .mat file(of desired name) with two variables of desired name(each variable of dimension 1xk) please let me know how to write a matlab code for this. Best Answer T=readtable('mycsv.csv'); % ^^^^^^^^^------ your csv filenamep=T{:,1};q=T{:,2};save('mymat.mat','p','q') % ^^^^^^^^^----- your resulting .mat filename Related SolutionsMATLAB: Fullfile to contain multiply file extension Try:filePatternCSV = fullfile(handles.sourceFolder, '*.csv'); csvFiles = dir(filePatternCSV); filePatternXLS = fullfile(handles.sourceFolder, '*.xls'); xlsFiles = dir(filePatternXLS);filePatternODS = fullfile(handles.sourceFolder, '*.ods'); odsFiles = dir(filePatternODS);allFiles= vertcat(csvFiles,xlsFiles,odsFiles); MATLAB: How to load a excel file in folder You can run a loop for all the (excel/csv) files in the folder. Go through the below lines of code:xlfiles = dir('*.csv'); % You are in the folder of csv files/ change extension accordingly Nfiles = length(xlfiles) ; % number of files% loop for each file for i = 1:Nfiles fname = xlfiles(i).name ; % file name data = xlsread(fname) ; % read the file %%do what you want %%%end Related QuestionRemoving the top rows of a csv fileHow to read Multiple CSV files in multiple sub foldersMerging multiple csv files into one mat file
Best Answer