[英]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.