Getting "Arrays have incompatible sizes for this operation." on this exercise

2 次查看(过去 30 天)
Hello im trying to create a discrete time signal and im getting Arrays have incompatible sizes for this operation. Its something on z = [u1 - u2];. Any help or advice?
close all;
clear all;
clc;
clf;
AM = 19390128
AM = 19390128
k = mod(AM,5)
k = 3
t = mod(AM,4)
t = 0
n = -50:50;
u = [zeros(3 + k) ones(3 + k)];
u1 = [zeros(n + 2 + k) ones(n + 2 + k)];
u2 = [zeros(n - 2 - t) ones(n - 2 - t)];
delta = [1,zeros(n - t)];
x = times(6,delta);
y = [u - x];
z = [u1 - u2];
Error using -
Arrays have incompatible sizes for this operation.
stem(z);

采纳的回答

Star Strider
Star Strider 2022-11-28
The ‘z’ assignment fails because the arrays used to calculate it are empty, likely because the first 50 elements of ‘n’ are less than or equal to zero, an ‘n’ is being used to define ‘u1’ and ‘u2’. However replacing ‘n’ with numel(n) in those assignments still results in incompatible array sizes, at least in part because a single numeric argument to zeros and ones (and similar functions) results in a matrix —
AM = 19390128
AM = 19390128
k = mod(AM,5)
k = 3
t = mod(AM,4)
t = 0
n = -50:50;
Sz_n = size(n)
Sz_n = 1×2
1 101
n_pos = nnz(n>0)
n_pos = 50
u = [zeros(3 + k) ones(3 + k)];
SzU = size(u)
SzU = 1×2
6 12
u1 = [zeros(n + 2 + k) ones(n + 2 + k)]
u1 = 101-D empty double array
u2 = [zeros(n - 2 - t) ones(n - 2 - t)]
u2 = 101-D empty double array
u1 = [zeros(numel(n) + 2 + k) ones(numel(n) + 2 + k)] % Use: numel(n)
u1 = 106×212
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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
delta = [1,zeros(n - t)];
x = times(6,delta);
y = [u - x];
z = [u1 - u2];
Arrays have incompatible sizes for this operation.
stem(z);
I leave that for you to resolve.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by