Error using reshape Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
266 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abdul Jabbar
le 28 Avr 2021
Réponse apportée : Abdul Jabbar
le 28 Avr 2021
Hi, I am trying to handle 3D matrices and regular vectors in a same line of code. Matrix and vector increase by 1 at each iteration.
Issue: Error using reshape. Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Description of Code:
obj.R = 0.1;
NUM_gz = 100;
NUM = 100,
initially NUM = 100 but after each iteration it increments by 1. whereas, NUM_gz remians fixed.
Which means at each my r(:,w) is [3, 1] vector and reshape(obj.D(1,w,:),[3, 1]) should convert it to [3, 1] so that dimensions remian consistant. apperently, there should not ne any error. However, I am getting the above error continuously.
I appreciate any help,
organ.r = zeros(3,NUM);
organ.D = zeros(3,NUM,3);
I am using these vectors and matrices within different functions and therefore object name might seem inconsistant but that is besides the point.
n1 = 64;
w = 1: length(obj.r)-obj.NUM_gz;
for n = 1:n1
L = obj.r(:,w) + obj.R * cos(2*pi*n/n1) * reshape(obj.D(1,w,:),[3, 1]) + obj.R * sin(2*pi*n/n1) * reshape(obj.D(1,w,:),[3, 1]);
plot3(L(1),L(2),L(3),'Color','k', 'linewidth', 0.1)
end
0 commentaires
Réponse acceptée
Steven Lord
le 28 Avr 2021
Set an error breakpoint and run your code. When you reach the line where you call reshape confirm that obj.D(1, w, :) is the size that you believe it to be. If it isn't identify for which value of the loop variable the problem occurs, set a conditional breakpoint (described on that same documentation page to which I linked above) on that line for when the loop variable reaches its previous value (so if the problem occurred for n = 9 stop when n == 8), and step through the loop to see when the size of obj.D(1, w, :) changes from what it should be.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!