using xlsread for cell variable

조회 수: 2 (최근 30일)
Yona
Yona 2014년 12월 24일
편집: Linda Cianciolo 2015년 1월 1일
I have a data store in .csv files. in the data i have vector of number that i want get in cell not in string (and some more data that i want in separate cell). because the vectors are not in same length i don't want it to be numbers.
Can we use xlsread or other function and store cell variable (in cell matrix)? If not what is the easiest way (format?) to store the data in csv file to change it in matlab from string/array to cell variable?
example file is attached
  댓글 수: 1
Linda Cianciolo
Linda Cianciolo 2015년 1월 1일
편집: Linda Cianciolo 2015년 1월 1일
Lets try the following, I hope this can help:
function C = claimReader()
inp = csv2struct(['C:\Documents and Settings\nkulczy\My Documents\085 Starry Sky\','Starry_Sky_inputs_vert.csv']);
inputTitles = [{'Output_Dir'};{'Claimz'};{'Prodz'};{'Fault_Locations'};{'Fault_Type'};{'Primary_Failed_Part'};{'Part_Group'};{'Selected_SEAG'};{'Change_Point'};{'Date_Compile'};{'Minimum_Date'}];
claim = inp.(cell2mat(inputTitles(2))); %returns a file path/location string
C = csv2struct(claim);
end
function Out = csv2struct(filename)
%%read xls file with a single header row
[~, ~, raw] = xlsread(filename);
[~ , ~, ext] = fileparts(filename);
if ~strcmpi(ext, '.csv') %convert non .csv files to .csv, so blanks stay blank
filename=[pwd,'tempcsv',datestr(now,'yymmddHHMMSSFFF'),'.csv'];
xlswrite(filename,raw);
[~ , ~, raw] = xlsread(filename);
delete(filename);
end
if size(raw,1)==11 && size(raw,2)==2 %transpose SS inputs (must match dimensions of input matrix EXACTLY!!!)
raw = raw';
end
nRow = size(raw,1);
nCol = size(raw,2);
header = raw(1,:);
raw(1,:) = [];
end

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

채택된 답변

Image Analyst
Image Analyst 2014년 12월 24일
I don't quite understand the question, but I'll take a guess. You can use csvread() to read in your data file, and xlswrite() to write it out to an Excel workbook. Does that answer the question?
  댓글 수: 5
Image Analyst
Image Analyst 2014년 12월 30일
Try this:
[xd, ~, xcell]=xlsread('example2.csv');
[rows, columns] = size(xcell)
for row = 1 : rows
% Extract string.
str = char(xcell(row, 3));
% Get rid of brackets
str = str(2:end-1);
% Turn into numbers and put in cell
column3{row} = sscanf(str, '%d, ');
end
% Display the cells
celldisp(column3)
column3
Yona
Yona 2015년 1월 1일
tnx

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

추가 답변 (1개)

Ilham Hardy
Ilham Hardy 2014년 12월 30일
In a very different approach,
Use
textscan
instead of
slxread or csvread

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by