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

2 ビュー (過去 30 日間)
SHU HUANG
SHU HUANG 2018 年 7 月 2 日
回答済み: Naga 2024 年 9 月 27 日
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

回答 (1 件)

Naga
Naga 2024 年 9 月 27 日
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.

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by