从Matlab中的两个不同矩阵生成图矩阵 [英] generate plot matrix from two different matrices in matlab

查看:219
本文介绍了从Matlab中的两个不同矩阵生成图矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个矩阵(5_by_1),比如说A = [5行1列]和B = [5行1列],如果我进行plot(A,B),我将创建一个大矩阵C = [ 5行5列]可以吗?!

I have two matrices (5_by_1), say A=[5 rows,1 column] and B=[5 rows, 1 column] if I do plot(A,B), I will create a large matrix C=[5 rows,5 columns] wright?!

现在,我想创建一个较大的矩阵而不绘制它.我直接想要这个矩阵.谢谢你. 例如A=[1 2 3 4 5 ]B=[3 4 2 1 4]

Now I would like to create this large matrix without plot it. I want this matrix directly. thank you. For example A=[1 2 3 4 5 ] and B=[3 4 2 1 4]

c=

 0     1     0     0     0
 1     0     0     0     1
 0     0     1     0     0
 0     0     0     1     0

推荐答案

这应该有效:

a = [1 2 3 4 5];
b = [3 4 2 1 4];

c = flipud(sparse(b,a,1,4,5));

如果您想查看完整的c:

If you want to see the full c:

full(c)

或者如果您使用更大的版本:

or if you have a bigger version:

c = flipud(sparse(b,a,1,max(b),max(a)));

flipud命令是​​将矩阵上下颠倒.

The flipud command is to flip the matrix upside down.

希望这对您有帮助=)

移动"矩阵,以使最低值在(1,1)中(在翻转之前).结构将是正确的,但是原点将不容易被发现.

"Shift" the matrices, so that your lowest value is in (1,1) (before you flip it). The structure will be correct, but the origin won't be easy to spot.

a_1 = floor(a - min(a)) + 1;  % floor if you don't have integers.
b_1 = floor(b - min(b)) + 1;

c = flipud(sparse(b_1,a_1,1,max(b_1),max(a_1)));

这篇关于从Matlab中的两个不同矩阵生成图矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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