Compare value of previous with current value

3 次查看(过去 30 天)
I need to compare the value of with todays value.Any ideas how to implement this?

回答(1 个)

Jaswanth
Jaswanth 2024-1-4
Hi,
I understand that you would like to extract data from a table by identifying with the month of current date to compare the values. To accomplish this task in MATLAB, you can use the 'readtable' function to read the Excel file into a table, and then you can filter the data to find the corresponding value for the current month.
You can follow the steps below to implement the same:
  1. Read the Excel file into MATLAB as a table.
  2. Convert the current date into a month number.
  3. Filter the table to find the rows where the month number matches the current month.
  4. Extract the value(s) from the third column for the matching month.
The following example code snippet demonstrates the above specified process:
% Assuming the Excel file is named 'monthly_data.xlsx'
filename = 'monthly_data.xlsx';
% Read the Excel file into a table
dataTable = readtable(filename);
% Create a char array with the current date
currentDate = '05-03-2023';
% Convert the char array to a datetime object and extract the month number
currentMonth = month(datetime(currentDate, 'InputFormat', 'dd-MM-yyyy'));
% Filter the table to find the rows with the matching month
matchingRows = dataTable(dataTable.MonthNumber == currentMonth, :);
% Extract the values from the third column for the matching month
matchingValues = matchingRows.ValueColumn; % Replace 'ValueColumn' with the actual name of the third column
% Display the matching values
disp(matchingValues);
Hope the solution provided above is helpful.
Thanks!

Community Treasure Hunt

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

Start Hunting!

Translated by