Extracting 2 columns from a excel file and send them to an own matrix file
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sergio
am 16 Feb. 2024
Kommentiert: Star Strider
am 17 Feb. 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 Kommentar
Akzeptierte Antwort
Star Strider
am 16 Feb. 2024
Bearbeitet: Star Strider
am 16 Feb. 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 Kommentare
Weitere Antworten (1)
Askic V
am 16 Feb. 2024
Bearbeitet: Askic V
am 16 Feb. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!