Filter löschen
Filter löschen

Identifying and plotting unique combinations of data

8 Ansichten (letzte 30 Tage)
fadzhi
fadzhi am 4 Feb. 2021
Kommentiert: fadzhi am 8 Feb. 2021
Dear all,
I am not really an expert at Matlab and needed help in the following function and will really appreciate it.
I have written a function to identify and plot the data belonging to a unique combination of first column= temperature and second clumn= strain rate (Total 16 combinations, please see attached file).......I am using 'unique' command to identify each value in the first column. However, i am not getting the desired plot of 16 curves. I think same temperature values in first column is problematic. Therefore, it is not able to identify it properly. The function is below:
kf1 = GetKf('AA7075');
[nT, nE] = size(kf1);
% plot all flow curves
figure; hold on;
for i=1:nT
for j=1:nE
if i==1
plot(kf0(i,j).e, kf0(i,j).s, 'r-');
elseif i==2
plot(kf0(i,j).e, kf0(i,j).s, '-');
else
plot(kf0(i,j).e, kf0(i,j).s, 'k-');
end
txt1=[num2str(kf0(i,j).T) ' C, ' num2str(kf0(i,j).e_dot) ' /s'];
text(kf0(i,j).e(end)+0.1, kf0(i,j).s(end), txt1);
end
end
function kf = GetKf(fname)
cname = ['load' fname '.txt;'];
eval(cname);
cname = ['kf_all=' fname ';'];
eval(cname);
Ts = unique(kf_all(:,1));
for i=1:length(Ts)
Tindx = find(kf_all(:,1)==Ts(i));
kf_T = kf_all(Tindx,2:4);
e_dots = unique(kf_T(:,1));
for j = 1:length(e_dots)
Eindx = find(kf_T(:,1)==e_dots(j));
kf(i,j).T=Ts(i);
kf(i,j).e_dot=e_dots(j);
kf(i,j).e = kf_T(Eindx,2);
kf(i,j).s = kf_T(Eindx,3);
end;
end;

Akzeptierte Antwort

lk
lk am 5 Feb. 2021
Hi fadzhi,
If I understand correctly, you are trying to find all unique combinations of column1 and column2 data. Here is an example of how you could do it, and get the data for columns 3 and 4 for each unique combination. Hope this helps.
tempStrainRate = kf_all(:, 1:2);
[Ts, ~, ib] = unique(tempStrainRate, 'rows');
indices = accumarray(ib, find(ib), [], @(rows){rows});
% for i, where i is your combination index from 1 to size(Ts, 1) %this gives you number of rows
% to get all data for a temp/strain rate combination,
kf_all(indices{i}, 1:4);
% to get just columns 3 and 4
kf_all(indices{i}, 3:4);
% to get individual columns
kf_all(indices{i}, 3);
kf_all(indices{i}, 4);
  2 Kommentare
fadzhi
fadzhi am 8 Feb. 2021
There is an small issue. Instead of getting all 16 x 2 unique combination, i am getting only 8 x 2. This is becuase a combination repeats multiple times. I have attached the data. Perhaps you have a suggestion?
kf_all = load('AA7075.txt');
tempStrainRate = kf_all(:, 1:2);
[Ts, ~, ib] = unique(tempStrainRate, 'rows');
% % % the indices code comes from here: https://www.mathworks.com/matlabcentral/answers/331309-matlab-find-unique-column-combinations-in-matrix-and-respective-index
indices = accumarray(ib, find(ib), [], @(rows){rows});
fadzhi
fadzhi am 8 Feb. 2021
the data was duplicated.....working fine now......many thanks for your answer

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Orange finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by