Alligning the output using fprintf
    3 views (last 30 days)
  
       Show older comments
    
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')
 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 Comments
Accepted Answer
  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');
fprintf('%13.3f%13.3f%13.3f%13.3f\n',[I;B;H*1e-3;mu]);
0 Comments
More Answers (0)
See Also
Categories
				Find more on Propagation and Channel Models in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

