Error in Matlab Data Filtering from an Excel FiIe
3 次查看(过去 30 天)
显示 更早的评论
I have an Excel file that I want Matlab to read, import, then filter (find code below). My problem is, the RowsToKeep variable outputs as an empty array, even though I know there are rows within the data that match the criteria of MLAT between 72 and 82.
Unfortunately, the Excel file I'm using is too large to upload here, even as a zip file. However, I've attached a snippet of the file here:
Also, after I run the code below, this is the output from Matlab:
Does anyone know why RowsToKeep gets filtered as an empty array, and how I can fix it? My Matlab code is as follows:
clc;
clear all;
close all;
% Read data from Excel file
data = readtable('MLAT_Sat2.xlsx');
% Convert table to array
data = table2array(data);
% Remove rows with any NaN values
data = data(~any(isnan(data), 2), :);
% Extract columns
%NOTE: column extraction begins at row 2 to ignore the column headings.
time = data(2:end, 1);
angle = data(2:end, 2); % degrees
inclination = data(2:end, 3); % degrees
lat = data(2:end, 4); % degrees
lon = data(2:end, 5); % degrees
alt = data(2:end, 6); % kilometers
MLAT = data(2:end, 7); % degrees
MLON = data(2:end, 8); % degrees
r = data(2:end, 9);
% Find rows to keep with MLAT between 72 and 82
RowsToKeep = find(MLAT >= 72 & MLAT <= 82);
% Filter the data based on RowsToKeep
Filter = data(RowsToKeep +1 , :);
filteredTime = Filter(:, 1);
filteredAngle = Filter(:, 2);
filteredInc = Filter(:, 3);
filteredLat = Filter(:, 4);
filteredLon = Filter(:, 5);
filteredAlt = Filter(:, 6);
filteredMlat = Filter(:, 7);
filteredMlon = Filter(:, 8);
filteredr = Filter(:, 9);
0 个评论
回答(1 个)
Peter Perkins
2024-5-31
编辑:Peter Perkins
2024-5-31
This seems like a lot of unnecessary extra code. Let the table you read in do the work for you.
%data = readtable('MLAT_Sat2.xlsx')
% create some fake data
data = table(45658+(0:9)',rand(10,1),rand(10,1),rand(10,1),rand(10,1),VariableNames=["Date" "Time" "Lat" "Lon" "Alt"])
% turn those excel timestamps into datetimes and make a timetable
date = datetime(data.Date,ConvertFrom="excel");
time = days(data.Time); % I'm just guessing here
data = table2timetable(data(:,["Lat" "Lon" "Alt"]),RowTimes=date+time)
filteredData = data(0.1 <= data.Alt & data.Alt <= .9,:)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!