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

2 visualizaciones (últimos 30 días)
SHU HUANG
SHU HUANG el 2 de Jul. de 2018
Respondida: Naga el 27 de Sept. de 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

Respuestas (1)

Naga
Naga el 27 de Sept. de 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.

Categorías

Más información sobre Data Import from MATLAB 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!

Translated by