Effacer les filtres
Effacer les filtres

How to compare two string columns from different tables?

4 vues (au cours des 30 derniers jours)
Ramo Rafsel
Ramo Rafsel le 12 Nov 2020
Modifié(e) : Ramo Rafsel le 30 Nov 2020
I have been trying to write a title for a plot using a table that I have for the variables (see the pictures), and I am aiming for the title to look like this: "Variable name" + " unit " + 10^"decimal point".
The struggle now is that I could not find out how to compare both the variable name colums between the two tables and I am also not sure how to write them in the title through a loop everytime. I ve had some trials but no success
for k = 1:numel(U)
X = T.Variable==U(k);
Var2=Variableunits.Variable;%the table that contains the units and the decimal factor that should be used.
Num2= size(Var2,1);
for j= 1:Num2
if strcmpi(Var2{i},U(k)) == 0 % in case the the a variable from the arrray U and from the column Var2 are identical, Im not sure if it is right.
title(Var2{i},Variableunits.unit,Variableunits.Faktor); % write the variable, its unit and factor (I know it is not written right.)
end
end
end
Thanks a lot in advance in case someone can help!
  2 commentaires
Walter Roberson
Walter Roberson le 12 Nov 2020
Please attach a sample subset of VariableUnits not just an image of it. Based on the image, I suspect that you are not accessing the columns properly.
Ramo Rafsel
Ramo Rafsel le 12 Nov 2020
Hi Walter, Thanks for the reply.
I just edited and attached a matlab table that contains the units and factor of the variables.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 12 Nov 2020
for j= 1:Num2
if strcmpi(Var2{i},U(k)) == 0 % in case the the a variable from the arrray U and from the column Var2 are identical, Im not sure if it is right.
Your for loop is in variable j, but you are indexing Var2 at i where i is not initialized in the code you posted. That would leave i as sqrt(-1) which would be an error as an index.
title(Var2{i},Variableunits.unit,Variableunits.Faktor); % write the variable, its unit and factor (I know it is not written right.)
Try
title(Var2{i},Variableunits.unit + " " + Variableunits.Faktor); % write the variable, its unit and factor (I know it is not written right.)
  2 commentaires
Walter Roberson
Walter Roberson le 12 Nov 2020
Modifié(e) : Walter Roberson le 12 Nov 2020
Us = {'E1_ABD_FoamEventCnt','E1_LD_ActualStatus','H1_PRESSURE_S15hPa','H2_PRESSURE_S03mmHg','H2_PRESSURE_S07mmHg','H2_TMP_PDmdaPa'};
U = categorical(Us);
for k = 1:numel(U)
Var2 = Variableunits.Variable;%the table that contains the units and the decimal factor that should be used.
Num2 = size(Var2,1);
for i = 1:Num2
if Var2(i) == U(k)
thisunit = Variableunits.Unit(i);
if ismissing(thisunit)
thisunitname = '';
else
thisunitname = string(thisunit);
end
title(string(Var2(i)) + " " + thisunitname + " " + string(Variableunits.Factor(i)), 'Interpreter', 'none');
end
end
end
Ramo Rafsel
Ramo Rafsel le 12 Nov 2020
Thanks a lot! It is working :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by