Problem with dimensions, filling a matrix in a for loop

I am trying to work out the root mean square of my data in sections of 2 seconds. However, the dimensions the matrix Az1 etc is causing an error; he is my code;
clc
clear all;
A = mydata
A1=Az(:,1);
A2=Az(:,2);
A3=Az(:,3);
A1star = padarray(Az1,[0 3],'symmetric','post');
A2star = padarray(Az2,[0 3],'symmetric','post');
A3star = padarray(Az3,[0 3],'symmetric','post');
for i = 1:(length(Az)/120);
A1(i,:) = Az1star(i:i+120*i);
RMS1(i) = sqrt(mean(A1(i,:).^2));
A2(i,:) = Az2star(i:i+120*i);
RMS2(i) = sqrt(mean(A2(i,:).^2));
A3(i,:) = Az3star(i:i+120*i);
RMS3(i) = sqrt(mean(A3(i,:).^2));
end
Endpoint = length(RMS3);
Val = (length(Az)/60);
time = linspace(0, Val, Endpoint);
figure (1)
plot(time,RMS1)
figure (2)
plot(time,RMS2)
figure (3)
plot(time,RMS3)
Any tideas how to fix this problem?

2 commentaires

>> help padarray
padarray not found.
No idea what it is, is supposed to do.
But, there is no Az1, etc., so it's not surprising that would be a problem.
Plus, creating variables of different names with a subscript difference is a sign of poor data design choice--use another level of indexing or a structure or some other similar storage instead.
paddarray is here

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 4 Fév 2014

0 votes

You "clear all" so no variable "Az" or "Az1" etc will be in your workspace. Not unless "mydata" is a function that does assignin('caller') which is a bad idea.
sorry guys that is an old code where I had changed variables names
the actual code is as follows;
clc
clear all;
A = mydata
A1a=A(:,1);
A2a=A(:,2);
A3a=A(:,3);
A1star = padarray(A1,[0 3],'symmetric','post');
A2star = padarray(A2,[0 3],'symmetric','post');
A3star = padarray(A3,[0 3],'symmetric','post');
for i = 1:(length(A)/120);
A1(i,:) = Az1star(i:i+120*i);
RMS1(i) = sqrt(mean(A1(i,:).^2));
A2(i,:) = Az2star(i:i+120*i);
RMS2(i) = sqrt(mean(A2(i,:).^2));
A3(i,:) = Az3star(i:i+120*i);
RMS3(i) = sqrt(mean(A3(i,:).^2));
end
Endpoint = length(RMS3);
Val = (length(Az)/60);
time = linspace(0, Val, Endpoint);
figure (1)
plot(time,RMS1)
figure (2)
plot(time,RMS2)
figure (3) plot(time,RMS3)

5 commentaires

dpb
dpb le 4 Fév 2014
So, what's the specific error instead of expecting someone to divine it?
Haha Divine it! I like that .. funny :)
Many apologies dpb for not being clear the error that is coming up is that the dimensions of A1(i,:) and Az1star don't match?
A1star = padarray(A1,[0 3],'symmetric','post');
There is no A1 prior to this reference to it??? There's an A1a and the like but no A1. Again I think you'd be better served to quit making all these similarly-name variables but that isn't the actual problem.
A1(i,:) = Az1star(i:i+120*i);
What does
size(A1)
size(Az1star)
tell you?
DPB I managed to solve my problem and youre absolutely right once I got rid of all the similar names it was easier! Thanks again for your guidance
Ps sorry for such an ill written problem!

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Question posée :

le 4 Fév 2014

Commenté :

le 6 Fév 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by