Extracting 2 columns from a excel file and send them to an own matrix file
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sergio
el 16 de Feb. de 2024
Comentada: Star Strider
el 17 de Feb. de 2024
Hello, I have an XLS file that I need to extract two columns from, and send them in the Workspace to an own file.
I do on the xlsx file:
D=readtable('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 10) % anger 10 rubrikrader slik at jeg kan ekstrahere kolonne entries mer effektivt
timetemp = D;({:,3}{:,4})
timetempdouble = str2double(D{:,3},{:,4});
In order to get the file called timetempdouble as an own file, with readable double-format. But this does not work. How can I extract those two columns, and what is the general command to say extract "n" columns from a xlsx file and convert it to doubles?
Thanks!
1 comentario
Respuesta aceptada
Star Strider
el 16 de Feb. de 2024
Editada: Star Strider
el 16 de Feb. de 2024
Perhaps something like this —
opts = detectImportOptions('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 9, 'VariableNamingRule','preserve');
opts = setvartype(opts, 4, 'double');
D=readtable('tempDataTrollhFlygpl.xlsx', opts) % anger 10 rubrikrader slik at jeg kan ekstrahere kolonne entries mer effektivt
ismt6 = all(cellfun(@(x)isempty(x),D{:,6})); % Check 6 (Seems To Be Empty)
if ismt6
D = removevars(D, 6); % If 'Var6' Is Empty, Remove It (Optional)
end
D % Edited 'D'
timetemp = D(:,[3 4]) % Create 'timetemp' From Variables 3 & 4
EDIT — (16 Feb 2024 at 19:13)
.
4 comentarios
Más respuestas (1)
Askic V
el 16 de Feb. de 2024
Editada: Askic V
el 16 de Feb. de 2024
Hello,
I would do something like this to extract the data, and then I would used writematrix like VBBV suggested to write into new file.
A = readtable('tempDataTrollhFlygpl.xlsx');
Values = str2double(A{4:end, 4});
Dates = datetime(A{4:end, 3}, 'InputFormat','dd-MMM-yyyy');
plot(Dates, Values)
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!