Alligning the output using fprintf

3 views (last 30 days)
Left Terry
Left Terry on 11 Feb 2025
Edited: Stephen23 on 11 Feb 2025
Hello. I would like to allign the output of I, B, H and mu on the right side but i have no idea how to do it. If anyone can help it would be great. Thanks is advance.
clear all, clc, close all, format short, % mirrored version
I = [0.0039 0.0038 0.2 0.402 0.628 0.837 1.069 1.234 1.436 1.666 1.79 2.05...
1.8 1.54 1.42 1.24 1.03 0.8 0.61 0.4 0.18 0 ...
-0.19 -0.46 -0.61 -0.8 -1.05 -1.24 -1.41 -1.63 -1.89 -2.05 ...
-1.78 -1.62 -1.42 -1.17 -0.97 -0.8 -0.6 -0.38 -0.18 0 ...
0.19 0.43 0.68 0.84 1.05 1.21 1.42 1.69 2.07];
B = [0.03 29.9 199 230 280 335 398 438 478 517 543 572 ...
554 525 510 488 458 416 375 319 238 127 ...
-7 -186.9 -255 -326 -397 -441 -477 -513 -554 -575 ...
-556 -536 -513 -482 -450 -420 -376 -317 -243 -126 ...
12.2 164.2 279 336 396 434 480 522 576];
subplot(2,1,1)
plot(I,B), grid on
title('B vs. I'),xlabel('I (A)'), ylabel('B (mT)')
n = 3e+3; % loops per meter
H = n*I;
subplot(2,1,2)
plot(H,B), grid on
title('B vs. H'),xlabel('H (A/m)'), ylabel('B (mT)')
mu = B./H;
mu0 = 4*pi*1e-7; % N/A^2 or H/m
fprintf('\n\tI (A)\t\tB (mT)\t\tH (A/m)\t\tμ (H/m)\n\n')
I (A) B (mT) H (A/m) μ (H/m)
for i = 1:length(I)
fprintf('\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n',I(i),B(i),H(i),mu(i))
end
0.004 0.030 11.700 0.003 0.004 29.900 11.400 2.623 0.200 199.000 600.000 0.332 0.402 230.000 1206.000 0.191 0.628 280.000 1884.000 0.149 0.837 335.000 2511.000 0.133 1.069 398.000 3207.000 0.124 1.234 438.000 3702.000 0.118 1.436 478.000 4308.000 0.111 1.666 517.000 4998.000 0.103 1.790 543.000 5370.000 0.101 2.050 572.000 6150.000 0.093 1.800 554.000 5400.000 0.103 1.540 525.000 4620.000 0.114 1.420 510.000 4260.000 0.120 1.240 488.000 3720.000 0.131 1.030 458.000 3090.000 0.148 0.800 416.000 2400.000 0.173 0.610 375.000 1830.000 0.205 0.400 319.000 1200.000 0.266 0.180 238.000 540.000 0.441 0.000 127.000 0.000 Inf -0.190 -7.000 -570.000 0.012 -0.460 -186.900 -1380.000 0.135 -0.610 -255.000 -1830.000 0.139 -0.800 -326.000 -2400.000 0.136 -1.050 -397.000 -3150.000 0.126 -1.240 -441.000 -3720.000 0.119 -1.410 -477.000 -4230.000 0.113 -1.630 -513.000 -4890.000 0.105 -1.890 -554.000 -5670.000 0.098 -2.050 -575.000 -6150.000 0.093 -1.780 -556.000 -5340.000 0.104 -1.620 -536.000 -4860.000 0.110 -1.420 -513.000 -4260.000 0.120 -1.170 -482.000 -3510.000 0.137 -0.970 -450.000 -2910.000 0.155 -0.800 -420.000 -2400.000 0.175 -0.600 -376.000 -1800.000 0.209 -0.380 -317.000 -1140.000 0.278 -0.180 -243.000 -540.000 0.450 0.000 -126.000 0.000 -Inf 0.190 12.200 570.000 0.021 0.430 164.200 1290.000 0.127 0.680 279.000 2040.000 0.137 0.840 336.000 2520.000 0.133 1.050 396.000 3150.000 0.126 1.210 434.000 3630.000 0.120 1.420 480.000 4260.000 0.113 1.690 522.000 5070.000 0.103 2.070 576.000 6210.000 0.093

Accepted Answer

Stephen23
Stephen23 on 11 Feb 2025
Edited: Stephen23 on 11 Feb 2025
I = [0.0039,0.0038,0.2,0.402,0.628,0.837,1.069,1.234,1.436,1.666,1.79,2.05,1.8,1.54,1.42,1.24,1.03,0.8,0.61,0.4,0.18,0,-0.19,-0.46,-0.61,-0.8,-1.05,-1.24,-1.41,-1.63,-1.89,-2.05,-1.78,-1.62,-1.42,-1.17,-0.97,-0.8,-0.6,-0.38,-0.18,0,0.19,0.43,0.68,0.84,1.05,1.21,1.42,1.69,2.07];
B = [0.03,29.9,199,230,280,335,398,438,478,517,543,572,554,525,510,488,458,416,375,319,238,127,-7,-186.9,-255,-326,-397,-441,-477,-513,-554,-575,-556,-536,-513,-482,-450,-420,-376,-317,-243,-126,12.2,164.2,279,336,396,434,480,522,576];
% subplot(2,1,1)
% plot(I,B), grid on
% title('B vs. I'),xlabel('I (A)'), ylabel('B (mT)')
n = 3e+3; % loops per meter
H = n*I;
% subplot(2,1,2)
% plot(H,B), grid on
% title('B vs. H'),xlabel('H (A/m)'), ylabel('B (mT)')
mu = B./H;
mu0 = 4*pi*1e-7; % N/A^2 or H/m
fprintf('\n I (A) B (mT) H (A/m) μ (H/m)\n\n');
I (A) B (mT) H (A/m) μ (H/m)
fprintf('%13.3f%13.3f%13.3f%13.3f\n',[I;B;H*1e-3;mu]);
0.004 0.030 0.012 0.003 0.004 29.900 0.011 2.623 0.200 199.000 0.600 0.332 0.402 230.000 1.206 0.191 0.628 280.000 1.884 0.149 0.837 335.000 2.511 0.133 1.069 398.000 3.207 0.124 1.234 438.000 3.702 0.118 1.436 478.000 4.308 0.111 1.666 517.000 4.998 0.103 1.790 543.000 5.370 0.101 2.050 572.000 6.150 0.093 1.800 554.000 5.400 0.103 1.540 525.000 4.620 0.114 1.420 510.000 4.260 0.120 1.240 488.000 3.720 0.131 1.030 458.000 3.090 0.148 0.800 416.000 2.400 0.173 0.610 375.000 1.830 0.205 0.400 319.000 1.200 0.266 0.180 238.000 0.540 0.441 0.000 127.000 0.000 Inf -0.190 -7.000 -0.570 0.012 -0.460 -186.900 -1.380 0.135 -0.610 -255.000 -1.830 0.139 -0.800 -326.000 -2.400 0.136 -1.050 -397.000 -3.150 0.126 -1.240 -441.000 -3.720 0.119 -1.410 -477.000 -4.230 0.113 -1.630 -513.000 -4.890 0.105 -1.890 -554.000 -5.670 0.098 -2.050 -575.000 -6.150 0.093 -1.780 -556.000 -5.340 0.104 -1.620 -536.000 -4.860 0.110 -1.420 -513.000 -4.260 0.120 -1.170 -482.000 -3.510 0.137 -0.970 -450.000 -2.910 0.155 -0.800 -420.000 -2.400 0.175 -0.600 -376.000 -1.800 0.209 -0.380 -317.000 -1.140 0.278 -0.180 -243.000 -0.540 0.450 0.000 -126.000 0.000 -Inf 0.190 12.200 0.570 0.021 0.430 164.200 1.290 0.127 0.680 279.000 2.040 0.137 0.840 336.000 2.520 0.133 1.050 396.000 3.150 0.126 1.210 434.000 3.630 0.120 1.420 480.000 4.260 0.113 1.690 522.000 5.070 0.103 2.070 576.000 6.210 0.093

More Answers (0)

Categories

Find more on Propagation and Channel Models in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!