getting the information from the figure

3 views (last 30 days)
kaivlya patel
kaivlya patel on 23 Apr 2020
Answered: BobH on 20 May 2020
I have a code consisting of 4 requirements and their respective 3 variants.
It means that for each requirements, there are 3 variants assigned. and the final combination is 3^4, which is 81 total combinations.
I have all the combinations in the figure with blue dots for the tradespace study. When i click any of the points out of the total plotted points in the figure, it is just showing the x and y coordinates.
I want to know that if click on any of the points in the figure, will it going to reflect the combination architecture from the code?
How can i know that which point represent which combination out of 81 total combinations?
I am attching the figure in this thread and also the code to have the proper idea.
Any help in this area would be much appreciated and for me it is much needed.
Thanking you guys in advance.
%Define architecture decisions
arch_deci = ["a";"b";"c";"d";]
%Define architecture decision options
arch_deci_options = [
"HPP" "PA" "EPP" ;
"HLS" "ELS" "PC" ;
"HFS" "FA" "EFS" ;
"MINT" "ELMINT" "PR" ;
]
%Define relative costs
arch_deci_cost = [
1.0 3.0 8.0 ;
6.0 4.0 1.0 ;
1.0 3.0 8.0 ;
3.0 8.0 0.0 ;
]
%Define relative utilities
arch_deci_util = [
6.17 3.83 5.00 ;
5.37 5.57 1.00 ;
6.17 3.83 5.00 ;
5.78 5.59 0.00 ;
]
%Define weighting factor costs
weight_cost = [5;5;5;5;]
%Calculation of Cost
sum_weight_cost = sum(weight_cost)
%Define weighting factors for utilities
weight_util = [1;1;1;1;]
%Calculation of utilities
sum_weight_util = sum(weight_util)
%Generate all possible architectures (without using any constraints on feasibility)
total_archs = 81;
n_arch=total_archs;
n_arch=0
archs = strings(total_archs,4);
for a=1:3
a_opt = arch_deci_options(1,a);
for b=1:3
b_opt = arch_deci_options(2,b);
for c=1:3
c_opt = arch_deci_options(3,c);
for d=1:3
d_opt = arch_deci_options(4,d);
n_arch = n_arch+1;
archs(n_arch,:) = [a_opt b_opt c_opt d_opt ];
end
end
end
end
n_arch % this number should match total_archs
% Calculate cost and util for each architecture
archs_cost = zeros(n_arch,1);
archs_util = zeros(n_arch,1);
for arch_idx = 1:n_arch
cost = 0;
util = 0;
for deci_idx = 1:4
deci_opt = archs(arch_idx,deci_idx);
[row,col] = find(arch_deci_options == deci_opt);
cost = cost + arch_deci_cost(row,col) * weight_cost(deci_idx,1);
util = util + arch_deci_util(row,col) * weight_util(deci_idx,1);
end
archs_cost(arch_idx,1) = cost/sum_weight_cost;
archs_util(arch_idx,1) = util/sum_weight_util;
end
%Find the Pareto frontier
pareto_frontier = zeros(5,3);
pareto_frontier_archs = strings(5,5);
frontier_idx = 0;
%Sort util in descending order (largest util in the top)
[archs_util_sorted,arch_idx] = sort(archs_util,'descend');
%Order the cost and archs as per the sorted util order
archs_cost_sorted = archs_cost(arch_idx,:);
archs_sorted = archs(arch_idx,:);
prev_min_cost = 255;
c_util = 255;
start = 1;
for util_idx = 2:n_arch
util = archs_util_sorted(util_idx,1);
if util == c_util
continue
end
temp_cost = archs_cost_sorted(start:util_idx,:);
[min_cost,temp_idx] = min(temp_cost);
if min_cost < prev_min_cost
prev_min_cost = min_cost;
%The index of the arch from arch_idx
pidx = (temp_idx - 1) + start;
frontier_pidx = arch_idx(pidx,:);
%Store the frontier point
frontier_idx = frontier_idx + 1;
pareto_frontier(frontier_idx,1) = frontier_pidx;
pareto_frontier(frontier_idx,2) = archs_cost_sorted(pidx,:);
pareto_frontier(frontier_idx,3) = archs_util_sorted(pidx,:);
%Store the frontier archs.
pareto_frontier_archs(frontier_idx,1) = frontier_pidx;
pareto_frontier_archs(frontier_idx,2:5) = archs(frontier_pidx,:);
end
%Restart
start = util_idx;
c_util = util;
end
Utopia = UtilityHighRange; % for plotting purposes add Utopia point
%Plot the tradespace and pareto frontier
plot(archs_cost,archs_util,'b.')
xlabel('Cost')
ylabel('Utility')
xlim([CostLowerRange CostHighRange])
ylim([UtilityLowerRange UtilityHighRange])
title('Trade Space Pareto')
hold on
plot(Utopia,'pg','LineWidth',5)
annotation('textarrow',[0.1657 0.1357],[0.8738 0.9238],'String','Utopia')
plot(pareto_frontier(1:frontier_idx,2), pareto_frontier(1:frontier_idx,3),'rs','LineWidth',3)
hold off

Accepted Answer

BobH
BobH on 23 Apr 2020
This older question/answer suggests adding the 'Tag' property to the plot.
It seems you could use pidx and frontier_idx to find the right information to tag.
  14 Comments
kaivlya patel
kaivlya patel on 20 May 2020
ohh ok. I try doing that too. And how can I export this coordinate values to the excel file using coomand, writematrix?
Any input in that?

Sign in to comment.

More Answers (1)

BobH
BobH on 20 May 2020
For recent versions of MATLAB (R2019a and after), the help on writematrix has useful examples that I think apply to your question.
If you have an older MATLAB, then assuming you have Windows, and assuming Microsoft Office is installed on your pc, you could use xlswrite. See https://www.mathworks.com/matlabcentral/answers/74322-export-data-from-matlab-to-excel
If you have new difficulties with writematrix, I suggest you create a fresh question to get more readers/helpers.

Community Treasure Hunt

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

Start Hunting!