简体   繁体   English

无法执行分配,因为左侧的索引与右侧的大小不兼容。?

[英]Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.?

F=[125 250 500 1000 2000 4000];
T = [1.1 1.0 0.85 0.8 0.65 0.55]
V = 4*5*2.8;
L_n = [76 78 81 84 83 80];
L_f = [80 81 86 87 86 82];
fi = [1];
fi(end+1) = 0.8*(V./T)

I want to add the values in to fi however i get the eror "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."我想将值添加到 fi 但是我得到错误“无法执行分配,因为左侧的索引与右侧的大小不兼容。”

This is my working code这是我的工作代码

F = [125 250 500 1000 2000 4000];
T = [1.1 1.0 0.85 0.8 0.65 0.55];
V = 56;
L_n = [76 78 81 84 83 80];
L_f = [80 81 86 87 86 82];
fi = 0.8 * (V ./ T);

and if you want the 1 at the beginning of the array, you can add如果你想要 1 在数组的开头,你可以添加

fi = [1, fi];

. .

Matlab matrices with more than 1 dimesion must have same number of elements for each value in one of the dimensions. Matlab 具有超过 1 个维度的矩阵必须在一个维度中的每个值具有相同数量的元素。

In your case, when fi is declared its dimension is 1x1 .在您的情况下,当fi被声明时,其尺寸为1x1 And you are trying to add 6 elements on the 2nd position of the first dimension.您正在尝试在第一个维度的第二个 position 上添加 6 个元素。 So, if that worked, you would end up with something like this: [[1],[a1 a2 a3 a4 a5 a6]] .所以,如果这有效,你最终会得到这样的结果: [[1],[a1 a2 a3 a4 a5 a6]] But that is not allowed.但这是不允许的。

If you still want to do that, you may want to use a cell array .如果您仍想这样做,您可能需要使用 元胞数组 Which allows you to add different elements.这允许您添加不同的元素。

Here you have an example:这里有一个例子:

fi = {1}
fi{end+1} = 0.8*(V./T)

Notice that some functions like sum won't work on a cell array and you would have to do some conversions.请注意,像sum类的某些函数不适用于元胞数组,您必须进行一些转换。

On the other hand if you expected to have a different output like this: [1 a1 a2 a3 a4 a5 a6] (like sugested on another answer).另一方面,如果您希望有一个不同的 output 像这样: [1 a1 a2 a3 a4 a5 a6] (就像在另一个答案中建议的那样)。 You may have different options including horzcat :您可能有不同的选择,包括horzcat

fi = horzcat([1],0.8*(V./T))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法执行分配,因为左侧的索引与右侧的大小不兼容。 这是什么意思? - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. What does this mean? 由于左侧的索引与右侧的大小不兼容,无法执行分配 - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side 无法执行分配,因为左侧的大小为 1×2,右侧的大小为 2×2 - Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 2-by-2 无法执行赋值,因为左侧的大小为 512×512,右侧的大小为 512×512×3 MATLAB - Unable to perform assignment because the size of the left side is 512-by-512 and the size of the right side is 512-by-512-by-3 MATLAB 无法执行分配,因为左侧和右侧具有不同数量的元素 - Unable to perform assignment because the left and right sides have a different number of elements 无法执行分配,因为左侧和右侧的元素数量不同。 MATLAB 错误 - Unable to perform assignment because the left and right sides have a different number of elements. MATLAB ERROR Matlab:无法执行赋值,因为左侧和右侧的元素数量不同 - Matlab: Unable to perform assignment because the left and right sides have a different number of elements Matlab错误:左侧已初始化,并且索引范围为空。 但是,右侧返回了一个或多个结果 - Matlab error: The left hand side is initialized and has an empty range of indices. However, the right hand side returned one or more results 提升分配运算符的左侧 - Promoting the left hand side of an assignment operator 无法执行分配,因为此类型的变量不支持点索引 - Unable to perform assignment because dot indexing is not supported for variables of this type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM