- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
"Error using horzcat, Dimensions of arrays being concatenated are not consistent."
1 次查看(过去 30 天)
显示 更早的评论
I keep on getting the:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error with my code when I try to graph. I tried looking at a few problems but nothing worked out. Does anyone have a solution for me to graph my data.
0 个评论
回答(1 个)
Hassaan
2024-1-16
编辑:Hassaan
2024-1-16
Check and ensure that the dimensions of ax and [zeros(nrep, 1) y] are compatible for plotting.
% Dummy data
tsim = 10; % Total simulation time
lambda = 2; % Rate parameter for the Poisson process
mu = 0; % Mean of the normal distribution for jumps
sigma = 1; % Standard deviation of the normal distribution for jumps
nrep = 5; % Number of repetitions (simulations)
delta = 1/10; % Time interval for simulations
% Call the function with dummy data
[p, y] = comppoisson(tsim, lambda, mu, sigma, nrep, delta);
function [p, y] = comppoisson(tsim, lambda, mu, sigma, nrep, delta)
% Number of intervals
nint = fix(tsim / delta);
% Initializing arrays
NEV = zeros(nrep, nint);
CNEV = zeros(nrep, nint);
N = poissrnd(lambda * delta, nrep, nint); % Poisson random numbers for each interval
y = zeros(nrep, nint + 1); % Initialize y with an extra column for zero padding
p = zeros(nrep, nint + 1); % Initialize p with an extra column for zero padding
for k = 1:nrep
for j = 1:nint
if N(k, j) > 0
CNEV(k, j) = sum(normrnd(mu, sigma, 1, N(k, j)));
end
end
p(k, 2:end) = cumsum(NEV(k, :));
y(k, 2:end) = cumsum(CNEV(k, :));
end
% Time axis
ax = 0:delta:tsim;
plot(ax, y);
xlabel('Time');
ylabel('Value');
title('Simulated Poisson Process Trajectories');
end
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Feel free to contact me.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!