MATLAB: Strcmp with or-condition

orstrcmp

Hello,
i have the following two tables:
Tab1=table('Size',[9 3],'VariableTypes',{'cell','double','double'},'VariableNames',{'Description','Year','Value'});
Tab1.Description(:)={'Gas','Gas','Gas','Pellets','Pellets','Pellets','Oil','Oil','Oil'};
Tab1.Year(:)=[2015,2020,2025,2015,2020,2025,2015,2020,2025];
Tab2=table('Size',[6 3],'VariableTypes',{'cell','double','double'},'VariableNames',{'Description','Year','Value'});
Tab2.Description(:)={'Wood','Wood','Wood','FW','FW','FW'};
Tab2.Year(:)=[2015,2020,2025,2015,2020,2025];
Tab2.Value(:)=[5,10,17,7,25,75];
I try the following calculation:
Tab1(strcmp(Tab1.Description,or('Gas','Oil')),'Value')=Tab2(strcmp(Tab2.Description,'FW'),'Value');
The or-part seems to be the problem. I want the Value of 'FW' from Tab2 as the Value of 'Gas' and 'Oil' in Tab1. My original table is way bigger, so seperate calculations like:
Tab1(strcmp(Tab1.Description,'Gas'),'Value')=Tab2(strcmp(Tab2.Description,'FW'),'Value');
Tab1(strcmp(Tab1.Description,'Oil'),'Value')=Tab2(strcmp(Tab2.Description,'FW'),'Value');
are not purposeful. Maybe an if-condition with
||
could help, but i dont know how.
I will greatly appreciate any assistance.

Best Answer

Generally I would recommend just writing out two lines as Adam proposed earlier.
But if you really want 'one line' with a list of strings to index then you could wrap it in a for loop :
for DescriptionIndex = {'Gas', 'Oil'}, Tab1(strcmp(Tab1.Description, DescriptionIndex),'Value')=Tab2(strcmp(Tab2.Description,'FW'),'Value'); end