How can I count and plot

18 views (last 30 days)
Sanghyeon Chang on 10 May 2023
Answered: Jaswanth on 5 Jan 2024
If I have a excel file looks like this, I'd like to plot time vs total number of count as shown below.
y-axis is the number of counts, while x-axis is the range.

Jaswanth on 5 Jan 2024
Hi,
I understand that you wish to extract data from an Excel file and display it in a chart format similar to the one you provided. To achieve this, you can import the data from Excel using the ‘readmatrix’ function and create a bar chart with the ‘bar’ function. If you need to calculate a running total over time, the ‘cumsum’ function can be utilized. It computes the cumulative sum of the elements, beginning from the start of the first array dimension with a size larger than 1.
Please go through the following MathWorks documentation to know more about the functions mentioned above:
Please go through the following example code showing how to plot from an Excel file using a bar chart in MATLAB.
% Assume the Excel file is named 'data.xlsx' and the data is in the first sheet
% The time data is in the first column and the count data is in the second column
% Read the table from the Excel file
% Extract the time data
time_data = data{:, 1};
% Extract the count data
count_data = data{:, 2};
% Replace empty cells or NaN values with zeros
count_data(isnan(count_data)) = 0;
% Calculate the cumulative total count
cumulative_count_data = cumsum(count_data);
% Create a bar chart
bar(time_data, cumulative_count_data);
% Set the labels and title
xlabel('Time');
ylabel('Cumulative Total Count');
title('Cumulative Count vs. Time from Excel Data');
Hope the above provided information is helpful.
Thanks.