필터 지우기
필터 지우기

saving .mat file with matrix instead of cell arrays

조회 수: 1 (최근 30일)
adi kul
adi kul 2019년 2월 13일
댓글: adi kul 2019년 2월 15일
Hello All,
Thanks to awesome people here, I could manage to cleanup my .csv files and could save them as .mat with following code:
clearvars
close all
clc
d = uigetdir();
filePattern = fullfile(d, '*.csv');
file = dir(filePattern);
x = cell(1, numel(file));
for k = 1 : numel(file)
baseFileName = file(k).name;
fullFileName = fullfile(d, baseFileName);
[filepath,name,ext] = fileparts(fullFileName);
x{k} = readtable(fullFileName);
fprintf('read file %s\n', fullFileName);
%fprintf('read file %s\n', baseFileName);
%writetable(x{k},fullFileName);
temp = table2struct(x{k}(3:end,:),'ToScalar',true);
save([name '.mat'],'-struct','temp')
end
Now the mat file is being created with cell array of column headers inside the .csv file. What I want is instead of cell arrays, I want to have it as matrix. I have preprogramed tool which plots the .mat arrays but these being cell arrays, I suspect that tool is not working.
your help is much appreciated
  댓글 수: 4
Gani
Gani 2019년 2월 15일
편집: Gani 2019년 2월 15일
Did you check what is inside temp before saving ? seems inside 'temp' you have cell arrays. Hence its saving cell array in matfiles.
adi kul
adi kul 2019년 2월 15일
yes, it's having 1x1 struct with all the parameter cell arrays

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by