Why do I receive the error that arrays have incompatible sizes for this operation?

1 次查看(过去 30 天)
When the code runs the error message reads:
  • Arrays have incompatible sizes for this operation
  • Error in line 5
  • D=A:(A-C)/B:C;
clear all
A=('initial value:');
B=('number of values:');
C=('final value:');
D=A:(A-C)/B:C;
E=3412.14.*D;
F=(3412.14/2544.5).*D;
G=550.*D;
table(D',E',F',G','VariableNames',{'D','E','F','G'})
  4 个评论
Joshua Lenhardt
Joshua Lenhardt 2022-3-24
I'm sorry I didn't see that there. Thank you so much for your help and time with this, it finally makes sense for me now.

请先登录,再进行评论。

回答(3 个)

Arif Hoq
Arif Hoq 2022-3-24
编辑:Arif Hoq 2022-3-24
try this:
A=input('initial value:');
B=input('number of values:');
C=input('final value:');
% A=2;
% B=10;
% C=20;
D=A:(C-A)/B:C;
E=3412.14.*D;
F=(3412.14/2544.5).*D;
G=550.*D;
table(D',E',F',G','VariableNames',{'D','E','F','G'})
  1 个评论
Arif Hoq
Arif Hoq 2022-3-24
A=2;
B=10;
C=20;
D=A:(A-C)/B:C;
E=3412.14.*D;
F=(3412.14/2544.5).*D;
G=550.*D;
table(D',E',F',G','VariableNames',{'D','E','F','G'})
ans = 0×4 empty table
whenever "final value-initial value"
A=2;
B=10;
C=20;
D=A:(C-A)/B:C;
E=3412.14.*D;
F=(3412.14/2544.5).*D;
G=550.*D;
table(D',E',F',G','VariableNames',{'D','E','F','G'})
ans = 11×4 table
D E F G ____ ______ ______ _____ 2 6824.3 2.682 1100 3.8 12966 5.0957 2090 5.6 19108 7.5095 3080 7.4 25250 9.9233 4070 9.2 31392 12.337 5060 11 37534 14.751 6050 12.8 43675 17.165 7040 14.6 49817 19.578 8030 16.4 55959 21.992 9020 18.2 62101 24.406 10010 20 68243 26.82 11000

请先登录,再进行评论。


Voss
Voss 2022-3-24
I guess those first three lines are supposed to be calls to input()
A=('initial value:');
B=('number of values:');
C=('final value:');
whos()
Name Size Bytes Class Attributes A 1x14 28 char B 1x17 34 char C 1x12 24 char
D=A:(A-C)/B:C;
Arrays have incompatible sizes for this operation.
As in:
A=input('initial value:');
B=input('number of values:');
C=input('final value:');
D=A:(A-C)/B:C;
  1 个评论
Voss
Voss 2022-3-24
Also, note that this:
D=A:(C-A)/B:C;
gives you one more element than was requested:
A = 0; % initial value
B = 10; % number of values
C = 1; % final value
D=A:(C-A)/B:C;
numel(D)
ans = 11
It's better to use linspace():
D = linspace(A,C,B);
numel(D)
ans = 10

请先登录,再进行评论。


DEBABRATA jana
DEBABRATA jana 2023-9-14
编辑:DEBABRATA jana 2023-9-14
B=imread('LOGO.bmp');
subplot(2,2,3),imshow(B),title('Watermark Image');
Wd=im2double(B);
DCTw=dct(Wd);
subplot(2,2,4),imshow(DCTw),title('DCT of Watermark Image');
DCTwi=(DCTw/2)+(DCTi/0.001);
WI=idct(DCTwi);
Arrays have incompatible sizes for this operation.
also
Arrays have incompatible sizes for this operation.
Error in DCTandIDCTwithWatermarkImage (line 17)
DCTwi=(DCTw/2)+(DCTi/0.001);
  1 个评论
DGM
DGM 2023-9-14
编辑:DGM 2023-9-14
The error means what it says. The arrays are not compatible sizes. So what size are they? Nobody knows what LOGO.bmp is, so nobody knows what size DCTw is. Similarly, nobody knows what size DCTi is or where it came from. You are the only person with access to that information.
Check the sizes of your arrays. If they came from the same source, one may have been subject to some operation (e.g. padding or differencing) which has altered its size.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by