How to solve error "Arrays have incompatible sizes for this operation?

3 ビュー (過去 30 日間)
Gabriela
Gabriela 2023 年 9 月 15 日
コメント済み: Mathieu NOE 2023 年 12 月 12 日
I'm trying to calculate the standard deviation of noise but when i run my code its giving me an error. I need help please.
this is my code:
L=load("ver.mat");
t_6=(0:numel(L.actual_ver)-0.005);
Ensembl_avg=mean(L.ver);
figure(1);
plot(t_6,Ensembl_avg);
hold on;
plot(t_6,L.actual_ver);
grid on;
xlabel('Time');
ylabel('Ensemble Average and Actual Signal');
title('Ensemble Average and Actual Signal VS Time:');
figure(2);
One_of_the_measurements=50;
plot(t_6,L.ver(One_of_the_measurements,:));
hold on;
plot(t_6,L.actual_ver);
xlabel('Time');
ylabel('Actual Signal and One Measurement');
title('Actual Signal and One Measurement VS Time');
Noise_calc=L.actual_ver-Ensembl_avg;
n=2:100;
for i6=1:length(Noise_calc)
std(Noise_calc(i6));
std((L.actual_ver-One_of_the_measurements)./sqrt(n));
end
Arrays have incompatible sizes for this operation.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 15 日
load('ver.mat')
size(actual_ver)
ans = 1×2
1 500
n=2:100;
size(n)
ans = 1×2
1 99
You are trying to use element-wise division of 1x500 and 1x99, which is not possible, thus you get the error.
Idk what you are trying to do with that particular operation/line of code, so I can not suggest anything. Please provide additional details as to what your goal is.
Also, you are trying to get the standard deviation of a scalar value, which does not make sense (atleast to me). What is the use of it?

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 9 月 18 日
hello
I tried to understand what you wanted to do, and so far my suggestion is as follows :
L=load("ver.mat");
t_6=(0:numel(L.actual_ver)-0.005);
Ensembl_avg=mean(L.ver);
figure(1);
plot(t_6,Ensembl_avg);
hold on;
plot(t_6,L.actual_ver);
grid on;
xlabel('Time');
ylabel('Ensemble Average and Actual Signal');
title('Ensemble Average and Actual Signal VS Time:');
figure(2);
One_of_the_measurements=50;
plot(t_6,L.ver(One_of_the_measurements,:));
hold on;
plot(t_6,L.actual_ver);
xlabel('Time');
ylabel('Actual Signal and One Measurement');
title('Actual Signal and One Measurement VS Time');
% std of noise for signal "L.actual_ver" minus "Ensembl_avg"
Noise_calc=L.actual_ver-Ensembl_avg;
std(Noise_calc) % ans = 0.1005
% std of noise for signal "L.actual_ver" minus "one of the measurements"
% for the 100 measurements (results are stored in S)
for k = 1:100 %( k = one of the measurements);
S(k) = std((L.actual_ver-L.ver(k,:)));
end
figure(3);
plot(S) % shows the std of noise for the 100 measurements (measurement number is the x axis)
  4 件のコメント
Image Analyst
Image Analyst 2023 年 12 月 11 日
I accepted it for him. 🙂
Mathieu NOE
Mathieu NOE 2023 年 12 月 12 日
haha thanks alot @Image Analyst :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by