when i type in [x(1:firstmax), f1(1:firstmax)] in matlab, i get a 1x202 matrix for some reason?? should i not be getting a 2xlength(firstmax) matrix?
Info
此问题已关闭。 请重新打开它进行编辑或回答。
Subscripted assignment dimension mismatch.
1 次查看(过去 30 天)
显示 更早的评论
x = -10:0.1:10;
lower_1 = zeros(numel(x), 2);
upper_1 = zeros(numel(x), 2);
f1 = trapmf(x,[-2 0 0 2]);
[ss, firstmax] = max(f1);
lower_1(1:firstmax, :) = [x(1:firstmax), f1(1:firstmax)];
upper_1(firstmax:end, :) = [x(firstmax:end, :), f1(firstmax:end, :)];
I get a subscripted assignment dimesnion mismatch error. Why is this??
1 个评论
回答(2 个)
Ingrid
2015-6-23
you should do this
lower_1(1:firstmax, :) = [x(1:firstmax)',f1(1:firstmax)'];
upper_1(firstmax:end,:) = [x(firstmax:end)', f1(firstmax:end)'];
since your x is a rowvector and not a columnvector or transpose x first
3 个评论
cwshep
2015-6-23
It is because firstmax:end is empty (since firstmax is greater than end). To do it this way it would need to be: "upper_1(firstmax:end, :) = [x(:,firstmax:end).', f1(:, firstmax:end).'];"
Note that it's good habit to do a .' than just a ', since if they are complex values the ' does a conjugate transpose.
Ingrid
2015-6-23
编辑:Ingrid
2015-6-23
look at what I have shown in the code above you should not index x as x(firstmax:end,:) because this will be empty since x has dimensions 1x201 so just leave out the last :
but even easier would be to FIRST transpose x as I have also commented and then f1 is also a column vector and all subsequent transposes are not required which makes your code easier to maintain
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!