English 中文(简体)
Matlab 中的矩阵尺寸+循环错误
原标题:Matrix dimension + loop error in Matlab

我有一个矢量“ Xt”, Xt 维度为12588 X 1。 从此矢量,我应用了这个代码:

S=sum (( ABs( Xt( 2) : end)- Xt( 1: end-1) ) ) =2;

得出一个数字,S是一乘1。

现在,我的目标是构建一个矢量S(Nx1),其中S的每个值取决于J和K,例如:

S=sum (abs( Xt (**J**: end)-Xt (**K**: end)-Xt (**K**: end-1))) =2;

起初我想到(我不想J超过126):

for j=2:126 k=1:125, S=sum((abs(Xt(j:end)-Xt(1:end-k))).^2); end; end;

I got the error: "Error using - Matrix dimensions must agree."

是维度问题还是循环问题?


我刚刚意识到这个代码管用

for j=2:2 k=1:1;

S=sum((abs(Xt(j:end)-Xt(1:end-k))).^2); end;

所以这真的是一个矩阵层面的问题!

最佳回答

结束这个问题:

这就是我两周前解决这个小问题的方式:

for j=2:2 k=1:1;
S=sum((abs(Xt(j:end)-Xt(1:end-k))).^2); end;

简单

(我刚来到Matlab)

问题回答

暂无回答




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Multiply a 3D matrix with a 2D matrix

Suppose I have an AxBxC matrix X and a BxD matrix Y. Is there a non-loop method by which I can multiply each of the C AxB matrices with Y?

matrix and vector template classes in c++

#include <array> template <typename T> class Vector4<T> { std::array<T, 4> _a; // or T _a[4]; ? }; template <typename T> class Matrix4<T> { std::array<...

Linear Independence Matrix

Suppose we have a m by n matrix A with rank m and a set K⊆{1..n} such that the columns of A indexed by K are linearly independent. Now we want to extend K and find a set L so that k⊆L and columns ...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Java large datastructure for storing a matrix

I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...

Checking row and column for a word in python

I am trying to create a checking program to see if the word is in a matrix horizontally or vertically. I have the code for checking the row, but would checking the column be similar to the row code? ...

热门标签