Borrar filtros
Borrar filtros

How can I count and plot

15 visualizaciones (últimos 30 días)
Sanghyeon Chang
Sanghyeon Chang el 10 de Mayo de 2023
Respondida: Jaswanth el 5 de En. de 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.

Respuestas (1)

Jaswanth
Jaswanth el 5 de En. de 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:
  1. ‘readmatrix’:https://www.mathworks.com/help/matlab/ref/readmatrix.html
  2. ‘bar’:https://www.mathworks.com/help/matlab/ref/bar.html
  3. ‘cumsum’:https://www.mathworks.com/help/matlab/ref/cumsum.html
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
data = readtable('data.xlsx');
% 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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by