using xlsread for cell variable

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 comentario

Linda Cianciolo
Linda Cianciolo el 1 de En. de 2015
Editada: Linda Cianciolo el 1 de En. de 2015
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

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 24 de Dic. de 2014

0 votos

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 comentarios

Yona
Yona el 25 de Dic. de 2014
no. i know how to read. my question is if i have an array saved in the file in format [1,2,3,4,5]. by xlsread() it export to matlab like a string. my question is if it is a way to get it in cell variable that contain an array.
Image Analyst
Image Analyst el 25 de Dic. de 2014
I still don't understand. How are you saving by xlsread()? xlsread() opens an Excel workbook and imports it into MATLAB. xlsread does NOT save an MATLAB variable/array in a file.
You say you "know how to read." Well, that reading is done by xlsread() so you say you know how to do it. Well if you do , then why are you asking how to read the workbook into a cell array???? That's exactly what xlsread, which you say you know how to use, does so why are you asking? Please clarify, or get a native English speaker to help translate.
Yona
Yona el 30 de Dic. de 2014
[xd,~,xcell]=xlsread('example2.csv');
In XCell(:,2) i want that column B ([139,53,33,20,12,11,8,6,5,5,3]) will be Cell of number and not a string.
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 el 1 de En. de 2015
tnx

Iniciar sesión para comentar.

Más respuestas (1)

Ilham Hardy
Ilham Hardy el 30 de Dic. de 2014
In a very different approach,
Use
textscan
instead of
slxread or csvread

Productos

Preguntada:

el 24 de Dic. de 2014

Editada:

el 1 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by