How can I put table cells in a plot title?

15 visualizaciones (últimos 30 días)
Ramo Rafsel
Ramo Rafsel el 10 de Nov. de 2020
Respondida: Jemima Pulipati el 28 de Nov. de 2020
I have two different table that contain data of variables. The first one contains the values and times of the variables and the second one contains the unit and the decimal point of each of the variables that I want to plot ( see the picture).
I have already made a loop that plots the data. I am trying to write something that compares the two tables, and then if the variable columns have both the same value (e. g. the same name of the variable), the unit and decimal point gets added into the plot title. This was my first idea:
Var1=T.Variable; %variable name column of the first table
Var2=AuswertungVorlage.Variable;%the variable name column of the second table
if cellfun(@isequal, Var1, Var2) %comparing both columns
title(Var1) %wrong and not completed.
The title that I would like to be printed should look somewhat like this : Variablename [unit] * 10^(decimal point).
Thanks a lot in advance for the help!
  4 comentarios
Mathieu NOE
Mathieu NOE el 10 de Nov. de 2020
I can try to further help but the input data (U) is missing
Ramo Rafsel
Ramo Rafsel el 10 de Nov. de 2020
Editada: Ramo Rafsel el 11 de Nov. de 2020
the input data (U) is the following, which I want to compare with the variables from the table that I uploaded a part of:
U ={'E1_ABD_FEventcnt','E1_LD_Act','H1_PRES_hPa','H2_PRES_S03mmHg','H2_PRESS','H2_TMP'};
I tried the following code, I get however no titles...
Var2=variableunits.Variable;% the variable name column of the second table
tf = strcmpi(U(k),Var2); % if one of the variable names (from u) match the Var2, the result is 1.
if (tf == true) % if the result is 1 or true -->
title(Var2,variableunits.unit,variableunits.Faktor)% --> plot the varable name, with the unit and the faktor
end
hold off

Iniciar sesión para comentar.

Respuestas (1)

Jemima Pulipati
Jemima Pulipati el 28 de Nov. de 2020
Hello,
From my understanding, you are trying to set the title of the plot with the values that are retrieved from any specific cells of the table.
Here is a sample code:
% Declaring some values for the table
Variable = {'H2TEMP';'H1TEMP'};
Decimal = [3;4];
units = {'mS/cm';'mS/cm'};
% Creating a sample table with some values
T = table(Variable, Decimal, units);
% Creating a string with the table values
titleString = append(T.Variable{1},' ',T.units{1}, num2str(T.Decimal(1)));
plot((1:10).^2);
% Puts the string created above as the title of the plot
title(titleString);
Here, the values from the first row of the table are retrieved and concatenated to form a string. This string is then passed onto the title of the plot.
The title in the output plot looks like this:
NOTE:
  1. num2str() is used to convert a number to a character array, which is useful while concatenating the strings.
  2. append() is used to combine strings

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by