how to do edit table type data and do sliding window in matlab

1 Ansicht (letzte 30 Tage)
SHU HUANG
SHU HUANG am 2 Jul. 2018
Beantwortet: Naga am 27 Sep. 2024
I have imported excel file into matlab and stored it as type of table, the file contains customers' name, number, date of purchase and other such kind of things. now what I to do is to achieve following function in matlab: 1. I can filter specific customer's record by entering his name 2. the showed records of this specific customer are sliding windows, every unit of the sliding windows is like from day1 to day 10 and next is from day5 to day15. so can anyone help me out ? the only hint I know is to use cell type, but I still don't know what is the code look like

Antworten (1)

Naga
Naga am 27 Sep. 2024
Hello Huang,
To achieve the functionality you described, you can follow these steps to filter records by a specific customer's name and then display the records in a sliding window format. Below is a sample code that demonstrates how to do this:
% Function to filter the table for records that match the specified customer's name.
function customerRecords = filterCustomerRecords(data, customerName)
customerRecords = data(strcmp(data.CustomerName, customerName), :);
end
% Function sorts the records by date and then displays them in a sliding window format.
% The window size and step size are adjustable.
function displaySlidingWindows(records, windowSize, stepSize)
records = sortrows(records, 'DateOfPurchase'); % Sort by date
numRecords = height(records);
for startIndex = 1:stepSize:(numRecords - windowSize + 1)
endIndex = startIndex + windowSize - 1;
disp(records(startIndex:endIndex, :)); % Display current window
end
end
% Example usage
customerName = 'John Doe';
windowSize = 10;
stepSize = 5;
% Filter and display records
customerRecords = filterCustomerRecords(data, customerName);
displaySlidingWindows(customerRecords, windowSize, stepSize);
Ensure that your table (data) has the correct column names and types as expected by the code. You can adjust the column names in the code to match those in your actual data.

Kategorien

Mehr zu Data Import from MATLAB 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!

Translated by