我正在尝试开发一个机器人模拟器.他可以进入虚拟世界(100x100字符矩阵).我可以给他命令,如"向右移动50个位置","向左移动80个位置"等.
我完成了所有这些事情.问题是我想通过在其最终位置存储"x"字符来显示机器人在屏幕中的最终位置.
例如,假设它的最终位置是(50,50),我应该在世界上存储ax char [50] [50].
我试过这样做:
world[50][50]="x";
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我想在矩阵的开头添加一个值,例如,我的矩阵是
0,0,0,0,0,0
0,1,1,1,0,0
1,0,0,1,0,0
1,1,1,0,0,0
Run Code Online (Sandbox Code Playgroud)
然后我想在第一列添加'1'或'0',因此它会变成这样
1,0,0,0,0,0,0
1,0,1,1,1,0,0
1,1,0,0,1,0,0
1,1,1,1,0,0,0
0,0,0,0,0,0,0
0,0,1,1,1,0,0
0,1,0,0,1,0,0
0,1,1,1,0,0,0
Run Code Online (Sandbox Code Playgroud)
我怎么能在MATLAB中做到这一点?
我在32位Ubuntu虚拟机上使用Eclipse来处理项目.在尝试实现结构时或者在尝试运行特定函数时,我遇到了一个大问题.功能就是这个:
int count (matrix m, int v[], int w[], int col) {
int r=0;
int j=0;
while (j < m.length) {
int k=0;
bool aux=true;
while (k < col && aux ){
if (v[k] == 1) {
if(m.i[j][k] != w[k])
aux=false;
}
k++;
}
if(aux) r++;
j++;
}
return r;
}
Run Code Online (Sandbox Code Playgroud)
此函数接收矩阵(在下面定义),带有1和0的向量(用于了解要搜索的列,具有我们要在这些列中搜索的值的向量以及列数(等于向量的长度)当它击中第二个"如果"它给我分段错误(我无法理解它是什么),我可以看到以这种方式定义它是不正确的,但我已经尝试过并且我可以好像找到了一种方法来访问向量中的值.这是我的结构矩阵:
typedef int *ind;
struct matrix {
ind *i;
int length;
};
typedef struct matrix matrix;
Run Code Online (Sandbox Code Playgroud)
在这个结构中,我的矩阵有一个指针和长度(行数); 指针指向一个指针向量(每行一个指针),这些指针中的每一个指向一个矢量,实际上是我的矩阵行.这里我的函数添加并创建一个空矩阵:
matrix emptyS(int n, int col) {
matrix m;
int d=0;
m.length=0; …Run Code Online (Sandbox Code Playgroud) 以下行:
a=[1;2;10;9]
eye(10)(a,:)
Run Code Online (Sandbox Code Playgroud)
返回:
[1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0]
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?为什么它得到了价值?
我有一个从互联网上下载的.txt财务报表.当它被下载时,细胞被逐列采集......搞砸了我以简单的方式重建语句的能力.
所以我的问题是如何逐列而不是逐行填充二维数组列.很明显,在一个循环中你必须跳过行,但我生锈了,并且无法解决这个简单的问题.帮忙.
这是我试图在53行和11列重建的 损益表PASTEBUCKET.COM/2303
和我正常的排序方式.哪个最有可能不会有很大用处
String [][] fs = new String[53][11];
while (input.hasNextLine())
{
for(int row=0;row<53;row++){
for (int col=0;col<11;col++){
fs[row][col] = input.nextLine();
System.out.printf("%s\t",fs[row][col]);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的目标是使三重for循环乘以矩阵X矩阵,我得到输入矩阵,我必须得到矩阵^ 2.
我收到错误"IndexOutOfRangeException" - 当我调试以下代码时,索引超出了数组的范围:
for (int i = 1; i < nodeList.Count+1; i++)
{
for (int j = 1; j < nodeList.Count+1; j++)
{
result[i, j] = "0";
for (int k = 1; k < nodeList.Count+1; i++)
{
if ((matrix[i, k] != null) && (matrix[k, j] != null))
{
n1 = Convert.ToInt32(matrix[i, k]);
n2 = Convert.ToInt32(matrix[k, j]);
n3 = Convert.ToInt32(result[i, j]);
total = n3 + n1 * n2;
_total = total.ToString();
result[i, j] = _total;
}
}
}
} …Run Code Online (Sandbox Code Playgroud) 想象一下矩阵:
a =
4
2
8
9
Run Code Online (Sandbox Code Playgroud)
我需要重复n次.如果n = 3,结果是:
a =
4
4
4
2
2
2
8
8
8
9
9
9
Run Code Online (Sandbox Code Playgroud) 可能的重复:
如何使用转换和矩阵获取SVG中元素的实际x / y位置
我需要获取在SVG中这样编写的元素的x / y位置:
<image
y="-421.28461"
x="335.27295"
id="image2991"
xlink:href="file:///C:/Users/tom/Documents/t.jpg"
height="369"
width="360"
transform="matrix(0.22297057,0.97482518,-0.97482518,0.22297057,0,0)" />
Run Code Online (Sandbox Code Playgroud)
这里给出了x&y属性,但是没有给出图像的实际位置。据我所知
变换矩阵[a,b,c,d,e,f] e&f分别在x和y中给出平移轴。但是
问题是,在这里都( e & f )被0。现在我可以我得到实际的x任何y这种形象?
我有一个矩阵列表如下:
myarrlist = [array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), array([[10, 20, 30],40, 50, 60],[70, 80, 90]])]
Run Code Online (Sandbox Code Playgroud)
和,
sum(myarrlist)/float(len(myarrlist))
Run Code Online (Sandbox Code Playgroud)
给了我以下结果(这就是我要求的:矩阵加法的结果是一个矩阵)
array([[ 5.5, 11. , 16.5],[ 22. , 27.5, 33. ],[ 38.5, 44. , 49.5]])
Run Code Online (Sandbox Code Playgroud)
但是,当我给予
from numpy import *
Run Code Online (Sandbox Code Playgroud)
对于使用dot()函数进行矩阵乘法,sum()函数不再给出矩阵作为结果,而是给出单个值(添加所有元素).我是python的新手,我猜numpy的sum()会覆盖对python内置sum()的调用.
我试图在没有循环的列表中添加矩阵,并找到适合它的内置sum().是否可以使用python sum()并仍然使用numpy的其他功能?
我有一些矩阵:
A = [ 1 2 3 4 5 6;
1 2 3 4 5 6]
B = [ 6 5 4 3 2 1;
6 5 4 3 2 1]
C = [ 1 2 3 4 5 6;
1 2 3 4 5 6]
Run Code Online (Sandbox Code Playgroud)
什么是制作以下矩阵的代码:
Result = [1 2 9 9 10 11 5 5 5 6;
1 2 9 9 10 11 5 5 5 6]
Run Code Online (Sandbox Code Playgroud)
注意:实际上,上面的矩阵是3个矩阵的总和,其上面已经重新排列,如下面的矩阵.#sum是基于列的总和.
1 2 3 4 5 6
1 2 3 4 …Run Code Online (Sandbox Code Playgroud)