showing similar value in x and y-axis in matlab

旧巷老猫 提交于 2019-12-24 09:26:11

问题


i have matrix as below; from the calculation there will be some value that will be have same value to each other when plotting in graph (i used scatter plot),

the question here is how to know/identify which calculation is giving the matching data and can it be stored in the table. i have tried used find function in matlab but error occured.
A = [2/3 -1/3 -1/3;
    -1/3 2/3 -1/3;
    -1/3 -1/3 2/3];
B=[0 0 0;
    0 0 1;
    0 1 0;
    0 1 1;
    1 0 0;
    1 0 1;
    1 1 0;
    1 1 1];
d= [2/3 -1/3 -1/3];
q = [0 0.5773 -0.5773];
for i = 1:size(B,1)
    p1 =  A * B(1,:)' -A * B(i,:)';
    dtransformation0a(i) = d*p1;
    qtransformation0a(i) = q*p1;
    p2 =  A * B(2,:)' -A * B(i,:)'
    dtransformation0b(i) = d*p2;
    qtransformation0b(i) = q*p2;
     p3 =  A * B(3,:)' -A * B(i,:)';
    dtransformation0c(i) = d*p3;
    qtransformation0c(i) = q*p3;
    p4 =  A * B(4,:)' -A * B(i,:)';
    dtransformation0d(i) = d*p4;
    qtransformation0d(i) = q*p4;
    p5 =  A * B(5,:)' -A * B(i,:)';
    dtransformation0e(i) = d*p5;
    qtransformation0e(i) = q*p5;
    p6 =  A * B(6,:)' -A * B(i,:)';
    dtransformation0f(i) = d*p6;
    qtransformation0f(i) = q*p6;
end
figure
 scatter(dtransformation0a,qtransformation0a,100,'b.')
hold on
scatter(dtransformation0b,qtransformation0b,100,'b.')
hold on

回答1:


I don't have access to a MATLAB interpreter right now so I can't test it myself, but this should work:

A = [2/3 -1/3 -1/3;
    -1/3 2/3 -1/3;
    -1/3 -1/3 2/3];
B = [0 0 0;
    0 0 1;
    0 1 0;
    0 1 1;
    1 0 0;
    1 0 1;
    1 1 0;
    1 1 1];
d = [2/3 -1/3 -1/3];
q = [0 0.5773 -0.5773];
for i = 1:size(B,1)
    p1 =  A * B(1,:)' -A * B(i,:)';
    dtransformation0a(i) = d*p1;
    qtransformation0a(i) = q*p1;
    p2 =  A * B(2,:)' -A * B(i,:)'
    dtransformation0b(i) = d*p2;
    qtransformation0b(i) = q*p2;
     p3 =  A * B(3,:)' -A * B(i,:)';
    dtransformation0c(i) = d*p3;
    qtransformation0c(i) = q*p3;
    p4 =  A * B(4,:)' -A * B(i,:)';
    dtransformation0d(i) = d*p4;
    qtransformation0d(i) = q*p4;
    p5 =  A * B(5,:)' -A * B(i,:)';
    dtransformation0e(i) = d*p5;
    qtransformation0e(i) = q*p5;
    p6 =  A * B(6,:)' -A * B(i,:)';
    dtransformation0f(i) = d*p6;
    qtransformation0f(i) = q*p6;
end

X = [dtransformation0a, dtransformation0b];    %Assuming dtransformation0a and dtransformation0b are row martices.
Y = [qtransformation0a, qtransformation0b];    %Assuming qtransformation0a and qtransformation0b are row martices.
my_points = [X';Y'];    %Each row of my_points will represent a particular point.
my_points = unique(my_points, 'rows');    %Get unique rows, hence points.

figure
scatter(my_points(:,1),my_points(:,2),100,'b.')

Let me know if you face any problem.

**

EDIT!!

**

As per your requirement stated, what I understood was that you want to display those calculations which yield the value, say, (0,0); if this is indeed what you want, you should be able to get it by replacing the loop part by:

my_point = [0, 0];
for i = 1:size(B,1)
    p1 =  A * B(1,:)' -A * B(i,:)';
    dtransformation0a(i) = d*p1;
    qtransformation0a(i) = q*p1;
    p2 =  A * B(2,:)' -A * B(i,:)'
    dtransformation0b(i) = d*p2;
    qtransformation0b(i) = q*p2;
     p3 =  A * B(3,:)' -A * B(i,:)';
    dtransformation0c(i) = d*p3;
    qtransformation0c(i) = q*p3;
    p4 =  A * B(4,:)' -A * B(i,:)';
    dtransformation0d(i) = d*p4;
    qtransformation0d(i) = q*p4;
    p5 =  A * B(5,:)' -A * B(i,:)';
    dtransformation0e(i) = d*p5;
    qtransformation0e(i) = q*p5;
    p6 =  A * B(6,:)' -A * B(i,:)';
    dtransformation0f(i) = d*p6;
    qtransformation0f(i) = q*p6;

    if(dtransformation0a(i)==my_point(1))
        fprintf("dtransformation0a => (%f = %f * %f;)\n",dtransformation0a(i),d,p1);
    end
    if(dtransformation0b(i)==my_point(1))
        fprintf("dtransformation0b => (%f = %f * %f;)\n",dtransformation0b(i),d,p2);
    end
    if(qtransformation0a(i)==my_point(2))
        fprintf("qtransformation0a => (%f = %f * %f;)\n",qtransformation0a(i),q,p1);
    end
    if(qtransformation0b(i)==my_point(2))
        fprintf("qtransformation0b => (%f = %f * %f;)\n",qtransformation0b(i),q,p2);
    end
end

I hope this is what you're looking for.



来源:https://stackoverflow.com/questions/15329460/showing-similar-value-in-x-and-y-axis-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!