To plot one stem with multiple values for data of different months. (2024)

25 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Amjad Iqbal vor etwa 10 Stunden

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months

Kommentiert: Mathieu NOE vor etwa 6 Stunden

Akzeptierte Antwort: Voss

  • Processed_results.zip

Dear MATLAB Experts,

I have data in .mat files, each corresponding to a particular month with selected_dates and brightness information.

Each month has a different number of output values (1, 2, 3, ..., N). I need to create a stem plot for each month, with the month on the x-axis and brightness on the y-axis.

For example, if D201701 has six values, the plot will show six values in one single stem, and the x-axis will display the month name.

Additionally, I want to annotate each stem value with a marker (e.g., . or *) to indicate the corresponding date. I have attached an image that shows the stem plot for multiple values, as well as the data and code.

To plot one stem with multiple values for data of different months. (2)

Thank you for guidance and help.

2 Kommentare

Keine anzeigenKeine ausblenden

Cris LaPierre vor etwa 8 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3168956

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3168956

Are you trying to duplicate the image you shared? If so, I don't see how this is a stem plot, since stem plots would all originate from a common horizontal line. It looks like a bunch of line plots to me.

Amjad Iqbal vor etwa 8 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169001

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169001

Bearbeitet: Amjad Iqbal vor etwa 8 Stunden

@Cris LaPierre

Yes, I actually wanted to emphasis that I want to plot one stem line for one month to show all the values corresponding to brightness. I understand from image its confusing.

@Voss understood the query and resolved. I appreicate both for time and efforts.

I will further norish the results.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Voss vor etwa 8 Stunden

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#answer_1461806

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#answer_1461806

  • Processed_results.zip

Maybe something along these lines:

unzip('Processed_results.zip')

% load the files

F = dir(fullfile('Processed_results','*.mat'));

NF = numel(F);

for ii = 1:NF

S = load(fullfile(F(ii).folder,F(ii).name));

F(ii).brightness = S.all_brightness_values;

F(ii).dates = S.selected_dates;

end

% count the number of dates and brightnesses in each file

N_dates = arrayfun(@(x)numel(x.dates),F);

N_brightness = arrayfun(@(x)numel(x.brightness),F);

assert(isequal(N_dates,N_brightness))

% collect date and brightness values into matrices;

% each column is a file, each row is a brightness/date

NB = max(N_brightness);

dates = NaT(NB,NF);

brightness = NaN(NB,NF);

for ii = 1:NF

dates(1:N_dates(ii),ii) = F(ii).dates;

brightness(1:N_brightness(ii),ii) = F(ii).brightness;

end

% construct datetime dt representing the start of each month

dt = datetime(year(dates(1,:)),month(dates(1,:)),1);

% markers to be used in plots

markers = '.*xo+^v<>sdph';

markers = repmat(markers,1,ceil(NB/numel(markers)));

% plot stems

figure('Position',[50 50 1500 600])

hold on

for ii = 1:NB

stem(dt,brightness(ii,:),'Marker',markers(ii),'MarkerSize',12)

end

xticks(min(dt):calmonths(1):max(dt))

To plot one stem with multiple values for data of different months. (6)

% or plot markers only

figure('Position',[50 50 1500 600])

hold on

for ii = 1:NB

plot(dt,brightness(ii,:),'LineStyle','none','Marker',markers(ii),'MarkerSize',12)

end

xticks(min(dt):calmonths(1):max(dt))

To plot one stem with multiple values for data of different months. (7)

2 Kommentare

Keine anzeigenKeine ausblenden

Amjad Iqbal vor etwa 8 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3168996

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3168996

@Voss I really appreciate your kind efforts and providing the solution.

This is what I wanted to plot and show the results. Once again Thank you.

To plot one stem with multiple values for data of different months. (9)

Voss vor etwa 8 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169026

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169026

You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Mathieu NOE vor etwa 7 Stunden

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#answer_1461856

In MATLAB Online öffnen

hello @Amjad Iqbal

I modified a bit your code

added one line in the first for loop

number_of_data_thismonth(k) = numel(brightnessValues); % <= added this line first

then modified the plot

% original plot

% for i = 1:numel(allDates)

% % Plotting the stem for each date

% stem(allDates(i), allBrightnessValues(i), 'filled');

% % Extracting time information

% time_info = datestr(allDates(i), 'HH:MM:SS');

% % Adding time information on top of each stem

% text(allDates(i), allBrightnessValues(i), time_info, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');

% end

% modified plot

nnn = 1+[0 c*msum(number_of_data_thismonth)]; % cumulative sum of nb of data per month

for i = 1:numel(number_of_data_thismonth)

ind_start = nnn(i);

ind_stop = nnn(i+1) - 1;

ll(i) = ind_stop - ind_start +1; % ll is equal to number_of_data_thismonth, so we have a working code

% Plotting the stem for each date

% x position is "center" data

ind = round(mean(ind_start:ind_stop));

stem(repmat(allDates(ind),ll(i),1), allBrightnessValues(ind_start:ind_stop), 'filled');

% Extracting time information

time_info = datestr(allDates(ind_start:ind_stop), 'HH:MM:SS');

% Adding time information on top of each stem

text(repmat(allDates(ind),ll(i),1), allBrightnessValues(ind_start:ind_stop), time_info, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');

end

your original plot looks like

To plot one stem with multiple values for data of different months. (12)

now the modified plot is :

To plot one stem with multiple values for data of different months. (13)

try it ; hope it helps - full code below

clear;clc;close;

% List all .mat files in the directory

matFiles = dir('*.mat');

% Initialize cell arrays to hold aggregated data

allBrightnessValues = [];

allDates = [];

% Loop through each .mat file

for k = 1:length(matFiles)

% Load the current .mat file

data = load(matFiles(k).name);

% Extract the data

brightnessValues = data.all_brightness_values;

dates = data.selected_dates;

% Ensure data consistency

if isrow(brightnessValues)

brightnessValues = brightnessValues';

end

number_of_data_thismonth(k) = numel(brightnessValues); % <= added this line first

% Convert dates to cell array of strings if necessary

if ischar(dates)

dates = cellstr(dates);

elseif isdatetime(dates)

dates = cellstr(datestr(dates, 'dd-mmm-yyyy HH:MM:ss'));

elseif iscell(dates)

dates = cellfun(@char, dates, 'UniformOutput', false);

else

error('Unexpected date format in file: %s', matFiles(k).name);

end

% Append the data to the aggregated vectors

allBrightnessValues = [allBrightnessValues; brightnessValues];

allDates = [allDates; dates];

end

% Convert the date strings to datetime format

allDates = datetime(allDates, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss');

% Display the size of the aggregated vectors

disp(['Total number of brightness values: ', num2str(length(allBrightnessValues))]);

disp(['Total number of dates: ', num2str(length(allDates))]);

% Plotting

figure;

hold on;

% original plot

% for i = 1:numel(allDates)

% % Plotting the stem for each date

% stem(allDates(i), allBrightnessValues(i), 'filled');

% % Extracting time information

% time_info = datestr(allDates(i), 'HH:MM:SS');

% % Adding time information on top of each stem

% text(allDates(i), allBrightnessValues(i), time_info, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');

% end

% modified plot

nnn = 1+[0 c*msum(number_of_data_thismonth)]; % cumulative sum of nb of data per month

for i = 1:numel(number_of_data_thismonth)

ind_start = nnn(i);

ind_stop = nnn(i+1) - 1;

ll(i) = ind_stop - ind_start +1; % ll is equal to number_of_data_thismonth, so we have a working code

% Plotting the stem for each date

% x position is "center" data

ind = round(mean(ind_start:ind_stop));

stem(repmat(allDates(ind),ll(i),1), allBrightnessValues(ind_start:ind_stop), 'filled');

% Extracting time information

time_info = datestr(allDates(ind_start:ind_stop), 'HH:MM:SS');

% Adding time information on top of each stem

text(repmat(allDates(ind),ll(i),1), allBrightnessValues(ind_start:ind_stop), time_info, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');

end

hold off;

title('Brightness Temperature vs. Date');

xlabel('Date');

ylabel('Brightness Temperature');

datetick('x', 'yyyy-mm-dd', 'keeplimits');

ylim([180 280])

%%

%Plotting

% figure;

% hold on;

% for i = 1:numel(allDates)

% % Plotting the stem for each date

% stem(allDates(i), allBrightnessValues(i), 'filled');

% % Extracting time information

% time_info = datestr(allDates(i), 'HH:MM:SS');

% % Adding time information on top of each stem

% text(allDates(i), allBrightnessValues(i), time_info, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');

% end

% hold off;

% title('Brightness Temperature vs. Date');

% xlabel('Date'); axis normal;

% ylabel('Brightness Temperature');

% datetick('x', 'yyyy-mm-dd', 'keeplimits');

2 Kommentare

Keine anzeigenKeine ausblenden

Amjad Iqbal vor etwa 7 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169096

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169096

@Mathieu NOE

I really appreciate the time and efforts to provide the solution. I have modified the plot and I wanted to plot a neat one. Attached one is the finest result. I am thank full for all the experts to respond promptly.

To plot one stem with multiple values for data of different months. (15)

I always get benifit from this platform to learn new ideas and adapt for several solutions.

Mathieu NOE vor etwa 6 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169126

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2121481-to-plot-one-stem-with-multiple-values-for-data-of-different-months#comment_3169126

you're welcome !!

nice plot BTW :)

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Tags

  • plot
  • image analysis
  • signal processing
  • vector
  • matrices

Produkte

  • MATLAB

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by To plot one stem with multiple values for data of different months. (17)

To plot one stem with multiple values for data of different months. (18)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

Kontakt zu Ihrer lokalen Niederlassung

To plot one stem with multiple values for data of different months. (2024)
Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 6241

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.