How to fix error using horzcat when trying to display?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to learn matlab. How am I supposed to display to values in the same line without getting horzcat error? What am I doing wrong? Any help is appreciated.
a = [-3.821; 0.135; 5.995; -5.557; -4.041; -3.094; -3.244; -3.074; -1.241; -4.216; -2.834; -0.424; 5.337; -0.088; 2.985; 4.136; 1.939; 6.031; -2.607; 3.340]
b = [-1.529; -2.882; 1.287; 3.822; 0.422; -4.387; 3.107; -3.513; 4.760; -5.205; 2.265; -4.442; 6.247; -2.788; -2.688; -1.761; 1.987; 4.484; 0.052; -2.763]
c = (a.^2 + b.^2).^(1/2)
d = atand(a./b)
e = d;
d(d<0)=360+d(d<0)
a =
-3.8210
0.1350
5.9950
-5.5570
-4.0410
-3.0940
-3.2440
-3.0740
-1.2410
-4.2160
-2.8340
-0.4240
5.3370
-0.0880
2.9850
4.1360
1.9390
6.0310
-2.6070
3.3400
b =
-1.5290
-2.8820
1.2870
3.8220
0.4220
-4.3870
3.1070
-3.5130
4.7600
-5.2050
2.2650
-4.4420
6.2470
-2.7880
-2.6880
-1.7610
1.9870
4.4840
0.0520
-2.7630
c =
4.1156
2.8852
6.1316
6.7445
4.0630
5.3683
4.4919
4.6680
4.9191
6.6983
3.6279
4.4622
8.2164
2.7894
4.0169
4.4953
2.7763
7.5153
2.6075
4.3347
d =
68.1908
-2.6819
77.8837
-55.4805
-84.0382
35.1940
-46.2358
41.1871
-14.6125
39.0071
-51.3673
5.4525
40.5083
1.8079
-47.9969
-66.9370
44.2995
53.3695
-88.8573
-50.4009
d =
68.1908
357.3181
77.8837
304.5195
275.9618
35.1940
313.7642
41.1871
345.3875
39.0071
308.6327
5.4525
40.5083
1.8079
312.0031
293.0630
44.2995
53.3695
271.1427
309.5991
>> X = ['The resultant force is', num2str(c),'kN and directed',num2str(d),'degrees measured counterclockwise from the positive x-axis.'];
disp(X)
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
0 commentaires
Réponses (1)
VBBV
le 15 Nov 2022
Modifié(e) : VBBV
le 15 Nov 2022
try with sprintf
a = [-3.821; 0.135; 5.995; -5.557; -4.041; -3.094; -3.244; -3.074; -1.241; -4.216; -2.834; -0.424; 5.337; -0.088; 2.985; 4.136; 1.939; 6.031; -2.607; 3.340];
b = [-1.529; -2.882; 1.287; 3.822; 0.422; -4.387; 3.107; -3.513; 4.760; -5.205; 2.265; -4.442; 6.247; -2.788; -2.688; -1.761; 1.987; 4.484; 0.052; -2.763];
c = (a.^2 + b.^2).^(1/2);
d = atand(a./b);
e = d;
d(d<0)=360+d(d<0);
X = sprintf('The resultant force is %0.1f kN and directed %0.1f degrees measured counterclockwise from the positive x-axis\n',c,d)
2 commentaires
VBBV
le 15 Nov 2022
Modifié(e) : VBBV
le 15 Nov 2022
a = [-3.821; 0.135; 5.995; -5.557; -4.041; -3.094; -3.244; -3.074; -1.241; -4.216; -2.834; -0.424; 5.337; -0.088; 2.985; 4.136; 1.939; 6.031; -2.607; 3.340];
b = [-1.529; -2.882; 1.287; 3.822; 0.422; -4.387; 3.107; -3.513; 4.760; -5.205; 2.265; -4.442; 6.247; -2.788; -2.688; -1.761; 1.987; 4.484; 0.052; -2.763];
c = (a.^2 + b.^2).^(1/2);
d = atand(a./b);
e = d;
d(d<0)=360+d(d<0);
for k = 1:length(d)
X = sprintf('The resultant force is %0.1f kN and directed %0.1f degrees measured counterclockwise from the positive x-axis\n',c(k),d(k))
end
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!