Searching for a matched string within nested cell and delivering the index
Mostra commenti meno recenti
I have a nested cell array which is called values.
In this example, there are 5 sub cells. Usually this number is variable from 1 to 30.
Each cell has two subsub cells:
- the first one, or values{5,1}{1,1}, has always only one char value (in this example, TOTAL or MGS)
- the second one, or values{5,1}{2,1}, has matrix consisting from tow columns: on the left - tempearature values, on the right - physical properties.
My goal is twofold:
- to find the sub cell containing the char value 'TOTAL' (values{5,1}) and somehow to get the index of the matrix (the output would be values{5,1}{2,1}).
- to get from the matrix the physical property at 298,15. If the value for room temperature is missing, take the closest value to the RT (the output would be 7 or 6 (if the value at room temperature is missing))
To adress the 1st problem, I have written my handmade solution. This code works if there is in the char TOTAL in a{5,1}{1,1}. However, this string could be elsewhere. In this case, I have a problem.
To find a solution for the 2nd question, I created following script, which from my point of view could be simplier to read.
for m = 1:numel(values)
for n = 1:numel(values(m))
a = values(m);
if string(a{5,1}{1,1}) == 'TOTAL'
k = a{5,1}{2,1}(:,1); %column with temp numbers
n = 298.15; %RT
[~,~,idx] = unique(round(abs(k-n)));
minVal = k(idx==1);
valueAtRT = sprintf('%f', a{1,1}{5,1}(length(a{1,1}{5,1})+idx));
break;
end
end
end
How can I do this?
Thanks for any help.

2 Commenti
Stephen23
il 8 Apr 2021
@Nazar Adamchuk: please upload sample data in a mat file by clicking the paperclip button.
Nazar Adamchuk
il 8 Apr 2021
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!