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
cwshep
2015 年 6 月 23 日
編集済み: cwshep
2015 年 6 月 23 日
Your x and f1 arrays are 1x201. Your upper_1 array is 201x2. Presumably you want to do a "x = x.'; f1 = f1.';" before your assignment to lower_1.
Actually, the cleanest and best way is probably to just change your first line to "x = [-10:0.1:10].';"
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!