Seeking help to fix a bug where variable comparisons in my code are performed within the same group instead of across different groups as intended.

92 views (last 30 days)
Dear MATLAB Community,
I am seeking help with revising my code to address a bug I've encountered. I’ve attached my existing code, and I’m focusing specifically on the last portion (lines 527–551).
The goal of my revision was to ensure the output updates correctly based on a new Excel sheet I’m using. However, I’ve noticed an issue with the comparisons being performed in the code. Instead of comparing variables across groups (e.g., size(MT) vs. circularity(LD) or size(MT) vs. circularity(AI)), the code appears to be comparing variables within the same group (e.g., size(MT) vs. circularity(MT)).
Would anyone have suggestions on how I can fix this issue to ensure the comparisons are performed correctly across the intended groups?
I would greatly appreciate any insights or suggestions. Please let me know your thoughts!
Thank you in advance for your time and help!

Answers (1)

Kanishk
Kanishk on 25 Nov 2024 at 11:03
Hello Isabella,
I understand you want to compare variables across groups. The current implementation sorts the mean of coeff” and takes the top 3 variables for comparison. Those 3 variables are all from the group “MT” which results in comparison from the same group.
To compare variables across different groups, the top variables must come from different groups. To filter top variables from different groups, logical indexing can be used.
Please look at the below code to filter variables from different groups.
[~, top] = sort(mean(abs(coeff(:, 1:2)), 2), "descend");
mt_top = top(top>=1 & top<=11);
ld_top = top(top>=12 & top<=22);
ai_top = top(top>=23 & top<=33);
These indices can be used categorize the variables based on their group.
On line 538,
rvar = table2array(tbl_sub(:, mt_top(r)));
cvar = table2array(tbl_sub(:, ld_top(c)));
and on line 541,
if r == num_vars, xlabel(tbl_sub.Properties.VariableNames{ld_top(c)}); end
if c == 1, ylabel(tbl_sub.Properties.VariableNames{mt_top(r)}); end
This produces the following plot.
To learn more about logical indexing, have a look at this blog posted on MATLAB Central.
Thanks
Kanishk

Community Treasure Hunt

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

Start Hunting!