CODE error correction
Afficher commentaires plus anciens
HI all,
would somebody please help me find out what should i do to plot and correct this script?
clear
clc;
B=1000; L=2000;Df=200; Sgama=.8;
nsamples=3000;
rmem = zeros(3,nsamples);
qult = zeros(1,nsamples);
for K=1:nsamples
while true
C = normrnd(620,147.64);
if C<=450 || C >= 800 || ismember(C,rmem(1,1:K-1)); continue; end
gama = normrnd(1.96,0.02);
if gama <= 1.92 || gama >= 1.98 || ismember(gama,rmem(2,1:K-1)); continue; end
fi = normrnd(3.76,1.1034);
if fi <= 2.7 || fi >= 16.3 || ismember(fi,rmem(3,1:K-1)); continue; end
rmem(:,K) = [C; gama; fi];
break
end
q=107.25+(100*fi);
dq=1+(.4*tan(fi*pi/180)*(1-sin(fi*pi/180)^2));
Sq=1+(.5*sin(fi*pi/180));
Nq = tan((pi/4)+(pi*fi/360)) * tan((pi/4)+(pi*fi/360)) * exp(pi*tan(fi*pi/180));
Nc = (Nq-1)*cot(fi*pi/180);
Sc=1+(.5* Nq / Nc);
Ngama = 2*(Nq+1)*tan(fi*pi/180);
qult(K)=(1.08*C*Nc*Sc)+(q*Nq*Sq*dq)+(429*Ngama);
end
surf( C(1,1:nsamples), fi(1,1:nsamples), qult );
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ERROR :
??? Index exceeds matrix dimensions.
Error in ==> graphQ at 27 surf( C(1,1:nsamples), fi(1,1:nsamples), qult );
1 commentaire
dimuthu chathuranga
le 8 Avr 2021
eroor occur communication somebody
help me
help me Réponses (3)
UJJWAL
le 25 Sep 2011
1 vote
Hi ,
I don't see any reason as to why thic code should not give an error. C is not a vector. It is a single number(or let us say C is a vector of dimension 1 by 1. In the surf function you are trying to access C(1,1:nsamples) which obviously goes beyond the length of C . So an error must occour.
As far as correction is concerned, it is difficult unless you tell the nature of this code and what it is that you want to do. I defined a vector C1 and stored the individual values of C in it. I did the same for fi . However in that case surf would not work as it will require a 2D matrix in the form of qult to work. I believe that you want to plot qult for corresponding values of C and fi. However for that u need to use Plot3. I used it but I got something weird. So unless the nature of the code is not made clear it is extremely difficult to comment on the nature of the solution.
Happy to Help
2 commentaires
Walter Roberson
le 25 Sep 2011
Good point about surf() being the wrong call.
Walter Roberson
le 25 Sep 2011
UUJWAL is correct: with that flow of code, you will need to store each accepted C and fi value. Just before your q= assignment would seem to be an appropriate location.
Vikash Anand
le 13 Déc 2021
clc;
clear all;
close all;
n=7;k=4;
num_bit=10000;
genpoly=cyclpoly(n,k,'max');
SNRdB=0:10;
SNR=10.^(SNRdB/10);
for i=1:length(SNR)
msg = randi(num_bit,k,[0,1]);
code=encode(msg,n,k,'cyclic/binary',genpoly);
[row, column]=size(code);
codevec=reshape(code.',1,row*column);
noise=awgn(codevec,SNRdB(i));
y=codevec+noise;
error=0;
for j=1:length(y)
if (y(j)>1&&codevec(j)==0)||(y(j)<0&&codevec(j)==1)
error=error+1;
end
end
error=error/num_bit;
m(i)=error;
end
y(y>0)=1;
y(y<0)=0;
decode_y=decode(y,n,k,'cyclic/binary',genpoly);
decmsg=reshape(decode_y,num_bit,k);
semilogy(SNRdB,m,'r','linewidth',2),grid on;
title(' Bit Error Rate verses SNR for Cyclic Code');
xlabel(' SNR(dB)');
ylabel('BER');
1 commentaire
Walter Roberson
le 10 Nov 2024
I do not understand how this is an answer to the question that was originally asked?
RAJESH
le 25 Sep 2024
Modifié(e) : Walter Roberson
le 25 Sep 2024
clc; clear all; close all;
% Input data points
x = [0 3 4 5 6]; % x-coordinates
y = [3 6 1 7 5]; % y-coordinates
% Number of intervals
N = length(x);
% Spline parameters (can be tuned for smoothness)
alpha = [0.5 0.8 0.7 0.6 0.9]; % Scale control parameters
r = 3 * ones(1, N); % Shape parameters
intervals = [0 5; 3 5; 0 4; 3 4; 5 6]; % Define intervals
% Derivative values (arbitrary initialization for now)
d = [5.5 -3.5 0.5 2.0 -6.0];
d1 = [3.5 -1.5 5.5 2.5 1.5];
% Prepare X1 and Y1 matrices for the initial interpolation data
X1 = zeros(4, 4); % Initialize X1 with zeros
x1 = [x(1) x(2) x(3) x(4)];
x2 = [x(2) x(3) x(4)];
x3 = [x(1) x(2) x(3)];
x4 = [x(2) x(3)];
t = [length(x1) length(x2) length(x3) length(x4)];
X1(1, 1:t(1)) = x1;
X1(2, 1:t(2)) = x2;
X1(3, 1:t(3)) = x3;
X1(4, 1:t(4)) = x4;
Y1 = zeros(4, 4); % Initialize Y1 with zeros
y1 = [y(1) y(2) y(3) y(4)];
y2 = [y(2) y(3) y(4)];
y3 = [y(1) y(2) y(3)];
y4 = [y(2) y(3)];
t = [length(y1) length(y2) length(y3) length(y4)];
Y1(1, 1:t(1)) = y1;
Y1(2, 1:t(2)) = y2;
Y1(3, 1:t(3)) = y3;
Y1(4, 1:t(4)) = y4;
% Loop to compute parameters
a = zeros(1, 4); % Initialize arrays for a(i) and b(i)
b = zeros(1, 4);
for i = 1:4
% Compute a(i) and b(i)
a(i) = (x(i+1) - x(i)) / (X1(i, t(i)) - X1(i, 1));
b(i) = (X1(i, t(i)) * x(i) - X1(i, 1) * x(i+1)) / (X1(i, t(i)) - X1(i, 1));
end
% Main loop for calculating terms and interpolation
iter = 1;
L = []; L1 = [];
for i = 1:4
rho = (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1)); % Calculate rho
% Calculate terms
term1 = (y(i) - alpha(i) * Y1(i, 1)) * (1 - (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))).^3;
term2 = (y(i+1) - alpha(i) * Y1(i, t(i))) * ((x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))).^3;
% Prevent accessing out of bounds
if i < N
term3 = (r(i) * (y(i) - alpha(i) * Y1(i, 1)) + (x(i+1) - x(i)) * d(i) - alpha(i) * d1(i, 1) * (X1(i, t(i)) - X1(i, 1))) * ...
(1 - (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))).^2 * (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1));
term4 = (r(i) * (y(i+1) - alpha(i) * Y1(i, t(i))) - ((x(i+1) - x(i)) * d(i+1)) + alpha(i) * d1(i, t(i)) * (x1(i, t(i)) - x1(i, 1))) * ...
(1 - (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))) * ((x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))).^2;
else
term3 = 0; % Handle boundary condition
term4 = 0; % Handle boundary condition
end
% Calculate numerator and denominator
numerator = term1 + term2 + term3 + term4;
denominator = 1 + (r(i) - 3) * (1 - (x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1))) * ((x(i) - X1(i, 1)) / (X1(i, t(i)) - X1(i, 1)));
% Calculate q(i)
q(i) = numerator / denominator;
end
% Plot the result
plot(x, y, '.k', 'markersize', 20); % Original data points
hold on;
plot(X1(1,:), Y1(1,:), 'b-'); % Interpolated fractal curve
xlabel('x');
ylabel('y');
title('Recurrent Rational Fractal Cubic Spline');
grid on;
Index in position 1 exceeds array bounds. Index must not exceed 1.
3 commentaires
EN-NEJJAR
le 10 Nov 2024
Modifié(e) : Walter Roberson
le 10 Nov 2024
%**************************************************************
% PARTIE 2 : Simulation du vent par la distribution de Weibull
%**************************************************************
% On a relevé 50 mesures de vitesses du vent pendant une journée
clear
clc
% Définir les données de vitesse
vitesse = [6.2 16.1 16.3 19.0 12.2 8.1 8.8 5.9 7.3 8.2...
16.1 12.8 9.8 11.3 5.1 10.8 6.7 1.2 8.3 2.3 ...
4.3 2.9 14.8 4.6 3.1 13.6 14.5 5.2 5.7 6.5 ...
5.3 6.4 3.5 11.4 9.3 12.4 18.3 15.9 4.0 10.4 ...
8.7 3.0 12.1 3.9 6.5 3.4 8.5 0.9 9.9 7.9];
% Tracer l'histogramme des fréquences avec un pas de vitesse de 2m/s
binWidth = 2;
binCtrs = 1:binWidth:20;
% Utilisation de hist pour afficher l'histogramme
[counts, edges] = hist(vitesse, binCtrs);
whos counts edges
% Tracer l'histogramme
bar(edges(1:end-1), counts / sum(counts), 'hist');
xlabel('vitesse');
ylabel('Frequency %');
ylim([0 0.1]);
hold on;
% Traçage automatique de la distribution de Weibull
% Estimation des paramètres de la distribution Weibull
paramEsts = wblfit(vitesse);
% Créer une grille de valeurs pour le tracé de la courbe de Weibull
xgrid = linspace(0, 20, 100);
% Calcul de la densité de probabilité de la distribution de Weibull
pdfEst = wblpdf(xgrid, paramEsts(1), paramEsts(2));
% Tracer la distribution de Weibull
line(xgrid, pdfEst, 'Color', 'r');
% Modifier l'apparence des barres de l'histogramme
h = get(gca, 'Children');
set(h, 'FaceColor', [0.9 0.9 0.9]);
% Titre et labels
xlabel('vitesse');
ylabel('Fréquence');
ylim([0 0.1]);
% Fin du tracé
hold off;
Walter Roberson
le 10 Nov 2024
You have edges(1:end-1) plotted against counts, but edges(1:end-1) is one shorter than counts is because edges and counts are the same size.
Walter Roberson
le 10 Nov 2024
d1 = [3.5 -1.5 5.5 2.5 1.5];
d1 is 1 x 5
term3 = (r(i) * (y(i) - alpha(i) * Y1(i, 1)) + (x(i+1) - x(i)) * d(i) - alpha(i) * d1(i, 1) * (X1(i, t(i)) - X1(i, 1))) * ...
You access d1(i,1). When i becomes 2 that would be d1(2,1). However, there is no d1(2,1), only d1(1,2)
Catégories
En savoir plus sur Exploration and Visualization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!