在Matlab中在x和y轴上显示相似的值 [英] showing similar value in x and y-axis in matlab

查看:119
本文介绍了在Matlab中在x和y轴上显示相似的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的矩阵如下: 从计算中得出,在图形中绘制时会有一些值彼此相同(我使用散点图), 这里的问题是如何知道/识别哪个计算正在给出匹配的数据,并将其存储在表中.我曾尝试在matlab中使用查找功能,但发生了错误.

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

解决方案

我现在无法访问MATLAB解释器,因此我自己无法对其进行测试,但这应该可以:

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.')

让我知道您是否遇到任何问题.

**

编辑!

**

根据您的要求,我了解到您想显示产生该值的计算,例如(0,0);如果确实是您想要的,则应该可以通过将循环部分替换为:

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 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

解决方案

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.

这篇关于在Matlab中在x和y轴上显示相似的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆