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
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Subscripted assignment dimension mismatch.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (2)
Ingrid
el 23 de Jun. de 2015
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 comentarios
cwshep
el 23 de Jun. de 2015
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
el 23 de Jun. de 2015
Editada: Ingrid
el 23 de Jun. de 2015
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
el 23 de Jun. de 2015
Editada: cwshep
el 23 de Jun. de 2015
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 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!