How can I link data from separate arrays?

2 Ansichten (letzte 30 Tage)
Matthew Weltevreden
Matthew Weltevreden am 26 Feb. 2021
Kommentiert: dpb am 27 Feb. 2021
Suppose you have an array [4 7 9 4 8 3] which represents a list of parameter values within a database. For example ‘4’ is the thickness of a plate which has an associated array containing location and temperature values (5x2 double) [0.55 0.16; 0.60 0.16; 0.65 0.15; 0.7 0.14; 0.75 0.12]. Each of the thickness values has an associated 5x2 array which is unique.
So the question I have is this: Is there a way I can link the location and temperature data arrays with the thickness values so that I can plot all the arrays which correspond to thickness value of ‘4’ without doing this manually?
  5 Kommentare
dpb
dpb am 26 Feb. 2021
Be more helpful to us to have information on how the corollary data are stored; generated; etc., ... to have some idea on how they are linked/associated.
Matthew Weltevreden
Matthew Weltevreden am 26 Feb. 2021
field1 = 'Data1';
field2 = 'Data2';
field3 = 'Data3';
Thickness1 = 19.0;
Thickness2 = 22.0;
Thickness3 = 32.0;
Temp_data1 = [0,-0.05;0.2,-0.13;0.4,0.25;0.6,0.64;0.8,0.56;1,-0.063];
Temp_data2 = [0,0.36;0.2,-0.15;0.4,-0.1;0.6,0.21;0.8,0.47;1,0.35];
Temp_data3 = [0,0.64;0.2,-0.22;0.4,-0.42;0.6,-0.11;0.8,0.28;1,-0.027];
value1={Thickness1,Temp_data1};
value2={Thickness2,Temp_data2};
value3={Thickness3,Temp_data3};
database = struct(field1,value1,field2,value2,field3,value3);
input_thickness = 20;
I've provided some more information to help with the question, assuming the data is part of a struct i would like to extract all the temp data which is larger than a given input thickness in this case 20 (i.e. Temp_data2 & Temp_data3)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 26 Feb. 2021
Bearbeitet: dpb am 26 Feb. 2021
Making harder than needs must be --
Thickness=[19.0;22.0;32.0];
Temp_data=cat(3l [0,-0.05;0.2,-0.13;0.4,0.25;0.6,0.64;0.8,0.56;1,-0.063];
[0,0.36;0.2,-0.15;0.4,-0.1;0.6,0.21;0.8,0.47;1,0.35];
[0,0.64;0.2,-0.22;0.4,-0.42;0.6,-0.11;0.8,0.28;1,-0.027]);
input_thickness = 20;
isWanted=(Thickness>input_thickness); % logical vector of locations wanted
data=Temp_data(:,:,isWanted); % return temperature data wanted
  5 Kommentare
Matthew Weltevreden
Matthew Weltevreden am 27 Feb. 2021
Thanks for the advice. I was also wondering what could be done if the Temp_data arrays are not identical i.e. if a 8x2 double was also part of the same database such as below?
[0.2,-0.23;0.25,0.029;0.3,0.3;0.35,0.56;0.4,0.78;0.45,0.93;0.5,1.021;0.55,1.02]
dpb
dpb am 27 Feb. 2021
That would then require something like the table with the 2D arrays a cells; you wouldn't be able to use the 3D array "trick" as the planes have to be the same dimension(*) to do that.
(*) It would require augmenting to the maximum size with NaN or somesuch to do that.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Hernia Baby
Hernia Baby am 26 Feb. 2021
The code below is one I assumed from your infomation.
Therefore, it might be different from what you want to do.
As the other members said, you need to give us enough input data.
Thickness = [4 7 9 4 8 3];
% create datas by the number of thickness datas
name = ("parts"+char('A'+(0:length(Thickness)-1'))');
LocTemp(:,:,1) = [0.55 0.16; 0.60 0.16; 0.65 0.15; 0.7 0.14; 0.75 0.12];
for i = 1:length(Thickness)-1
LocTemp(:,:,i+1) = LocTemp(:,:,i) + 0.01;
end
% seperate data into location and temperature
Location = squeeze(LocTemp(:,1,:))';
Temperature = squeeze(LocTemp(:,2,:))';
% integration as cell type
for i = 1:length(Thickness)
C(i,:) = {name(i),Thickness(i),Location(i,:),Temperature(i,:)};
end
% legends
leg = {'name' 'thickness' 'location' 'temperature'};
% convert type
S = cell2struct(C, leg, 2);
% output example
S(1)
>> S(1)
name: "partsA"
thickness: 4
location: [0.5500 0.6000 0.6500 0.7000 0.7500]
temperature: [0.1600 0.1600 0.1500 0.1400 0.1200]
  1 Kommentar
Matthew Weltevreden
Matthew Weltevreden am 26 Feb. 2021
also works very well with previous example! Thank you!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by