Contents

% Ponieważ nie można użyć funkcji publish dla skryptów zawierających
% polecenie input skrytp został zmodyfikowany, tak aby uniknąc problemów
% wynikajacych z tego ograniczenia. Linijki zawierające polecenie input
% zostały zastąpione odpowiednim fragmentem, np.:
%   userinput = 123
%   if ~exist('userinput', 'var')
%       userinput = input('Input your input');
%   end
% W celu przetsestowania przykładów zawierających polecenie input należy
% zakomentować linijkę, w które zaincjalizowano zmienną, której wartość ma
% być określona jako wynik polecenia input (w powyższym przykładzie jest to
% linia userinput = 123).

Operacje wejścia/wyjścia

help exist
 EXIST  Check existence of variable, script, function, folder, or class
    EXIST(NAME) returns:
      0 if NAME does not exist
      1 if NAME is a variable in the workspace
      2 if NAME is a file with extension .m, .mlx, or .mlapp, or NAME
        is the name of a file with a non-registered file extension 
        (.mat, .fig, .txt).
      3 if NAME is a MEX-file on the MATLAB search path
      4 if NAME is a Simulink model or library file on the MATLAB search path
      5 if NAME is a built-in MATLAB function. This does not include classes
      6 if NAME is a P-code file on the MATLAB search path
      7 if NAME is a folder
      8 if NAME is a class (EXIST returns 0 for Java classes if you
        start MATLAB with the -nojvm option.)
 
    EXIST('NAME','builtin') checks only for built-in functions.
    EXIST('NAME','class') checks only for classes.
    EXIST('NAME','dir') checks only for folders.
    EXIST('NAME','file') checks for files or folders.
    EXIST('NAME','var') checks only for variables.
 
    NAME can include a partial path, but must be in a folder on the search
    path, or in the current folder. Otherwise, name must include a full path.
 
    If NAME specifies a file with a non-registered file extension 
    (.mat, .fig, .txt), include the extension.
 
    NAME is case insensitive on Windows systems, and case sensitive for 
    files and folder on UNIX systems.
 
    MATLAB does not examine the contents or internal structure of a file 
    and relies solely on the file extension for classification.
 
    See also DIR, WHAT, ISEMPTY, PARTIALPATH.

    Reference page in Doc Center
       doc exist

    Other functions named exist

       Composite/exist    inline/exist

radius = 5
if ~exist('radius', 'var')
    radius = input('Wprowadź wartość promienia [mm]: ')
end
radius =

     5

litera = 'a'
if ~exist('litera', 'var')
    litera = input('Wprowadź łańcuch: ','s')
end
litera =

    'a'

lancuch = 'Ala ma kota'
if ~exist('lancuch', 'var')
    lancuch = input('Wprowadź łańcuch: ','s')
end
length(lancuch)
lancuch =

    'Ala ma kota'


ans =

    11

lancuch = ' '
if ~exist('lancuch', 'var')
    lancuch = input('Wprowadź łańcuch: ','s')
end
lancuch =

    ' '

lancuch = ''
if ~exist('lancuch', 'var')
    lancuch = input('Wprowadź łańcuch: ','s')
end
length(lancuch)
lancuch =

  0×0 empty char array


ans =

     0

t=11
liczba = t
if ~exist('liczba', 'var')
    liczba = input('Wprowadź wartość zmiennej: ')
end
t =

    11


liczba =

    11

Funkcja eval

macierz = magic(20);
expression = 'magic'
if ~exist('expression', 'var')
    expression = input('Wprowadź nazwę zmiennej: ','s')
end
if (exist(expression,'var'))
    contour(eval(expression),100)
end
expression =

    'magic'

Funkcja dips

help disp
 DISP Display array.
    DISP(X) displays array X without printing the array name or 
    additional description information such as the size and class name.
    In all other ways it's the same as leaving the semicolon off an
    expression except that nothing is shown for empty arrays.
 
    If X is a string or character array, the text is displayed.
 
    See also FPRINTF, SPRINTF, INT2STR, NUM2STR, RATS, FORMAT, DETAILS.

    Reference page in Doc Center
       doc disp

    Other functions named disp

       cdfepoch/disp                 ntree/disp
       classregtree/disp             opaque/disp
       codistributed/disp            ProbDist/disp
       codistributor1d/disp          ProbDistUnivKernel/disp
       codistributor2dbc/disp        ProbDistUnivParam/disp
       Composite/disp                qfft/disp
       dataset/disp                  realp/disp
       distributed/disp              serial/disp
       dtree/disp                    sym/disp
       ftp/disp                      tall/disp
       gmdistribution/disp           timer/disp
       gpuArray/disp                 tunableGain/disp
       icgroup/disp                  tunablePID/disp
       imaqchild/disp                tunablePID2/disp
       imaqdevice/disp               tunableSS/disp
       inline/disp                   tunableSurface/disp
       instrument/disp               tunableTF/disp
       iviconfigurationstore/disp    varyingGoal/disp
       laurmat/disp                  vrfigure/disp
       laurpoly/disp                 vrnode/disp
       modem/disp                    vrworld/disp
       mtree/disp                    wdectree/disp
       NaiveBayes/disp               wptree/disp
       network/disp

z = 2 + 3i
z1 = 10 + 5i;
z2 = 5 + 10i;
z =

   2.0000 + 3.0000i

disp(z)
   2.0000 + 3.0000i

disp('Konfucjusz powiedział: ''Podróż tysiąca mil zaczyna się od jednego kroku..''');
Konfucjusz powiedział: 'Podróż tysiąca mil zaczyna się od jednego kroku..'
disp([z1 z2])
  10.0000 + 5.0000i   5.0000 +10.0000i

d=22;
disp(['dzisiaj jest środa ' num2str(d) ' marca'])
dzisiaj jest środa 22 marca
more on
disp(rand(100,7))
more off
disp('koniec tablicy')
%keyboard
    0.7470    0.8384    0.5711    0.8414    0.2597    0.1693    0.7454
    0.3099    0.5454    0.8132    0.3064    0.5917    0.9301    0.9091
    0.9165    0.9612    0.0862    0.1912    0.2276    0.2082    0.5846
    0.7823    0.0755    0.1921    0.0651    0.9551    0.0198    0.9065
    0.1010    0.9338    0.6295    0.9460    0.0630    0.6016    0.0567
    0.2811    0.3594    0.0639    0.2448    0.1832    0.6074    0.5567
    0.9075    0.0669    0.7430    0.6254    0.6242    0.4689    0.0030
    0.1111    0.9659    0.6034    0.2067    0.2914    0.5963    0.1532
    0.7898    0.6495    0.7984    0.2417    0.1372    0.7235    0.4075
    0.1023    0.4206    0.1606    0.7434    0.1889    0.4081    0.2334
    0.7679    0.5964    0.7379    0.1560    0.9566    0.5976    0.5353
    0.6621    0.3471    0.7570    0.8232    0.2966    0.4257    0.3116
    0.7731    0.2176    0.8813    0.0940    0.2372    0.1218    0.7086
    0.9320    0.0378    0.4292    0.9798    0.6602    0.3500    0.5871
    0.1769    0.1534    0.1875    0.6532    0.0043    0.5467    0.2392
    0.0204    0.3734    0.3030    0.2841    0.0782    0.1271    0.0641
    0.8336    0.8768    0.3208    0.8672    0.3096    0.0815    0.0034
    0.4732    0.4411    0.4420    0.0301    0.2240    0.2895    0.1891
    0.1086    0.6378    0.3619    0.7609    0.6953    0.6768    0.4912
    0.0891    0.3878    0.6256    0.8962    0.7002    0.4570    0.6165
    0.1151    0.8372    0.9388    0.6189    0.8518    0.4992    0.1228
    0.1680    0.7663    0.2869    0.7207    0.5591    0.0585    0.1330
    0.9725    0.1256    0.2446    0.4639    0.5703    0.0736    0.3142
    0.2860    0.0927    0.9209    0.7589    0.5309    0.3379    0.0879
    0.5990    0.6603    0.9262    0.0071    0.8589    0.3361    0.4088
    0.8522    0.3777    0.3099    0.1935    0.4463    0.9850    0.2823
    0.2448    0.1078    0.0765    0.0915    0.3834    0.7517    0.6306
    0.7272    0.6238    0.7809    0.1679    0.5954    0.6465    0.2198
    0.4008    0.6216    0.1307    0.9422    0.3050    0.8829    0.6543
    0.3106    0.9116    0.4615    0.8494    0.1011    0.5119    0.1935
    0.6538    0.6061    0.4402    0.1373    0.3719    0.3762    0.0946
    0.3918    0.4853    0.6050    0.6607    0.2222    0.8838    0.9184
    0.1193    0.5767    0.1270    0.0385    0.6432    0.2458    0.5582
    0.9785    0.9821    0.5990    0.1482    0.7767    0.1640    0.4176
    0.5183    0.5186    0.1321    0.1848    0.4300    0.6586    0.1104
    0.5078    0.3487    0.1153    0.6454    0.6211    0.2556    0.5527
    0.3250    0.9829    0.4411    0.8566    0.2791    0.1576    0.1113
    0.1973    0.9920    0.2711    0.8534    0.4780    0.2766    0.2360
    0.8629    0.8962    0.9441    0.4940    0.3147    0.2987    0.1387
    0.2679    0.7416    0.5166    0.7809    0.8272    0.0059    0.3282
    0.5387    0.6647    0.4453    0.2747    0.7432    0.2287    0.3464
    0.5515    0.7334    0.3086    0.9674    0.1443    0.6701    0.9288
    0.9633    0.4359    0.4696    0.9905    0.0683    0.9817    0.8883
    0.2696    0.3996    0.7794    0.0844    0.5321    0.2561    0.7900
    0.2657    0.2179    0.1688    0.3298    0.7440    0.6192    0.0745
    0.3100    0.8816    0.0225    0.2683    0.8357    0.9718    0.4198
    0.5573    0.9421    0.7087    0.2159    0.7207    0.4922    0.3967
    0.3782    0.9490    0.6051    0.7670    0.8876    0.3010    0.4129
    0.2458    0.1064    0.4137    0.3651    0.1629    0.5971    0.9740
    0.6762    0.0580    0.9148    0.1540    0.2012    0.5434    0.2379
    0.2613    0.1637    0.4772    0.1650    0.8820    0.1298    0.1086
    0.9615    0.5275    0.9162    0.8934    0.4620    0.5522    0.8000
    0.4976    0.0697    0.4969    0.9458    0.1870    0.1491    0.0448
    0.4278    0.0101    0.9276    0.5175    0.7249    0.2585    0.9600
    0.5678    0.0917    0.7037    0.0184    0.8836    0.5287    0.8016
    0.6130    0.6074    0.6946    0.4193    0.7980    0.8134    0.9606
    0.8070    0.0561    0.0046    0.1221    0.8430    0.7185    0.7657
    0.8808    0.6581    0.5402    0.9518    0.5380    0.5008    0.6082
    0.1600    0.5758    0.4130    0.2702    0.2096    0.8940    0.9890
    0.0892    0.0738    0.6281    0.8937    0.5304    0.9507    0.5626
    0.3131    0.2416    0.5435    0.8952    0.8433    0.4624    0.4959
    0.6074    0.3512    0.2160    0.7755    0.2153    0.2876    0.2530
    0.3787    0.1267    0.5521    0.9088    0.7167    0.9264    0.1960
    0.9255    0.7394    0.8627    0.0167    0.8627    0.4963    0.4927
    0.0570    0.4457    0.0049    0.9593    0.4713    0.8773    0.7109
    0.9940    0.0176    0.1251    0.0753    0.4605    0.2132    0.9876
    0.6670    0.6817    0.7751    0.2851    0.9425    0.1144    0.3346
    0.6171    0.8808    0.0204    0.4881    0.6283    0.1243    0.2202
    0.1479    0.1398    0.1426    0.9706    0.8064    0.5741    0.3453
    0.0290    0.8109    0.3204    0.5681    0.4015    0.4664    0.0916
    0.5725    0.2529    0.9048    0.2740    0.3214    0.3740    0.6316
    0.0300    0.0244    0.6142    0.1291    0.3788    0.7546    0.3782
    0.7115    0.5307    0.0159    0.1552    0.7190    0.4556    0.8874
    0.2140    0.9349    0.3114    0.2688    0.1931    0.7060    0.4265
    0.2552    0.7693    0.1928    0.4339    0.4900    0.9295    0.8908
    0.9586    0.4048    0.2755    0.3959    0.1208    0.8205    0.2242
    0.1819    0.7178    0.0267    0.4252    0.1399    0.0398    0.7969
    0.7985    0.4813    0.8306    0.6144    0.9472    0.9662    0.8583
    0.0400    0.4412    0.7643    0.4468    0.6309    0.8880    0.4271
    0.3092    0.9424    0.7212    0.0120    0.4387    0.6388    0.5889
    0.9671    0.5788    0.8227    0.0343    0.7078    0.0110    0.0917
    0.2670    0.7836    0.7645    0.3988    0.5296    0.9773    0.2506
    0.1219    0.7148    0.1206    0.9795    0.6524    0.3855    0.5938
    0.6074    0.1422    0.3843    0.5428    0.7782    0.3997    0.5206
    0.6454    0.6929    0.0279    0.9124    0.6180    0.5103    0.9141
    0.8744    0.3936    0.0013    0.3242    0.5021    0.5516    0.6633
    0.8973    0.1278    0.0070    0.2905    0.4854    0.9589    0.4997
    0.0532    0.6409    0.1678    0.8790    0.1101    0.8554    0.6348
    0.7595    0.4975    0.1504    0.7791    0.9165    0.4767    0.0864
    0.8589    0.0640    0.5155    0.3944    0.4326    0.8778    0.0408
    0.4817    0.5235    0.4189    0.8823    0.4270    0.3899    0.7516
    0.0751    0.3145    0.5938    0.4257    0.0293    0.0492    0.3238
    0.0907    0.8549    0.2770    0.4664    0.5104    0.3074    0.0665
    0.2002    0.0090    0.5928    0.4249    0.9637    0.3202    0.9233
    0.7783    0.2026    0.5851    0.4552    0.2754    0.4613    0.0544
    0.4073    0.8806    0.1216    0.6954    0.7434    0.4881    0.0679
    0.8270    0.2180    0.0786    0.0956    0.1168    0.7067    0.5735
    0.1480    0.3177    0.0321    0.7335    0.7693    0.3673    0.4392
    0.7329    0.3440    0.1682    0.1300    0.7657    0.9414    0.0274
    0.1499    0.8001    0.5242    0.4965    0.5408    0.2682    0.0497

koniec tablicy
more(10)
disp(rand(100,7))
more off
disp('koniec tablicy')
    0.2386    0.1959    0.8903    0.9766    0.6457    0.9838    0.0207
    0.1273    0.9748    0.0821    0.2203    0.1535    0.6930    0.7923
    0.6303    0.5751    0.7815    0.0841    0.0522    0.7025    0.1908
    0.4764    0.5832    0.8487    0.3589    0.0151    0.3713    0.9521
    0.1100    0.9500    0.4509    0.7332    0.1964    0.0641    0.7702
    0.4354    0.1000    0.6053    0.6021    0.5277    0.4435    0.8166
    0.9019    0.8787    0.3545    0.4514    0.1477    0.5430    0.4261
    0.5658    0.8915    0.7591    0.9128    0.0731    0.5402    0.3002
    0.7306    0.2140    0.5894    0.0032    0.5548    0.7863    0.6803
    0.9810    0.1670    0.6116    0.5101    0.9813    0.6014    0.8585
    0.5882    0.6461    0.8432    0.1445    0.1629    0.9470    0.8718
    0.5032    0.1803    0.4570    0.5046    0.1566    0.6312    0.8971
    0.5316    0.1165    0.8828    0.5682    0.1637    0.8788    0.8436
    0.6063    0.3653    0.4936    0.6422    0.0785    0.1227    0.4852
    0.7643    0.4024    0.6229    0.2069    0.7184    0.8135    0.4885
    0.6006    0.0898    0.5622    0.3402    0.4463    0.9776    0.0653
    0.7226    0.6838    0.7217    0.3275    0.5101    0.2312    0.4570
    0.4352    0.5469    0.5468    0.6150    0.6051    0.9127    0.5956
    0.6465    0.9860    0.7844    0.5912    0.8831    0.6764    0.1101
    0.1767    0.2127    0.4464    0.6879    0.1219    0.7251    0.3438
    0.8765    0.9190    0.9119    0.1664    0.2903    0.6858    0.2641
    0.2517    0.6652    0.0866    0.6522    0.0623    0.7967    0.5802
    0.3565    0.7435    0.9989    0.7686    0.1435    0.5296    0.4354
    0.3033    0.3785    0.7276    0.3958    0.0680    0.7546    0.4151
    0.9678    0.4748    0.5584    0.3963    0.1851    0.5036    0.0542
    0.1923    0.1063    0.1428    0.6921    0.7687    0.9070    0.2597
    0.0979    0.8838    0.8376    0.2377    0.8977    0.1236    0.2442
    0.6938    0.4451    0.7252    0.9489    0.5183    0.8522    0.7091
    0.0960    0.6682    0.4174    0.1358    0.8446    0.1750    0.6589
    0.1994    0.7282    0.2732    0.5115    0.2288    0.7642    0.1192
    0.6071    0.2856    0.3147    0.0414    0.4284    0.4593    0.1292
    0.7097    0.5937    0.5817    0.3124    0.3683    0.6061    0.0780
    0.8905    0.3705    0.6894    0.3218    0.6960    0.3640    0.7352
    0.6026    0.7956    0.8639    0.9483    0.9444    0.4019    0.5561
    0.8625    0.0735    0.2109    0.2073    0.2179    0.7301    0.8344
    0.6760    0.9927    0.5068    0.4893    0.7530    0.9551    0.1061
    0.7850    0.7760    0.4250    0.4447    0.5198    0.8788    0.2566
    0.5366    0.0074    0.2397    0.8208    0.7601    0.6097    0.0541
    0.0044    0.8889    0.7575    0.0175    0.8809    0.9678    0.6566
    0.1986    0.8641    0.7919    0.7885    0.2375    0.6341    0.2774
    0.4387    0.6976    0.3859    0.5408    0.9397    0.7773    0.7091
    0.5583    0.8850    0.3181    0.0455    0.0272    0.8985    0.1303
    0.3851    0.4656    0.4809    0.5139    0.5615    0.2266    0.5240
    0.6469    0.3716    0.2785    0.4456    0.8905    0.1013    0.0459
    0.5857    0.0830    0.1580    0.4914    0.1670    0.8283    0.1013
    0.7663    0.9972    0.3954    0.6599    0.4252    0.4245    0.4689
    0.1746    0.8698    0.2855    0.5054    0.3269    0.7271    0.7106
    0.5031    0.0001    0.2431    0.7419    0.5676    0.9367    0.6013
    0.3827    0.6800    0.6425    0.9438    0.8270    0.2965    0.2049
    0.9772    0.6549    0.9569    0.7993    0.3917    0.3122    0.6188
    0.9361    0.4118    0.1863    0.4377    0.6214    0.5497    0.6992
    0.8927    0.4764    0.9095    0.0903    0.9652    0.5526    0.3148
    0.4435    0.3883    0.5687    0.9336    0.8285    0.6404    0.8048
    0.7515    0.4521    0.1935    0.3784    0.8134    0.5966    0.1780
    0.9094    0.0268    0.7042    0.7589    0.9551    0.1612    0.2413
    0.3733    0.4253    0.6516    0.8038    0.1831    0.4179    0.5947
    0.1163    0.1058    0.3319    0.8042    0.6704    0.3691    0.8682
    0.5251    0.0431    0.5216    0.5958    0.7356    0.0803    0.8187
    0.3411    0.5561    0.0248    0.3250    0.8196    0.2363    0.5901
    0.8494    0.6113    0.0223    0.7483    0.6810    0.9943    0.0023
    0.1862    0.7388    0.7985    0.4765    0.3301    0.9093    0.9445
    0.2087    0.2569    0.1078    0.5156    0.0347    0.7908    0.7925
    0.5304    0.7263    0.6888    0.4801    0.1202    0.1351    0.3993
    0.0843    0.7133    0.7750    0.4240    0.2837    0.5503    0.8734
    0.2408    0.5038    0.7915    0.1760    0.8382    0.0538    0.6744
    0.6346    0.8928    0.7095    0.2806    0.9014    0.6766    0.2424
    0.1111    0.7794    0.9465    0.8777    0.4499    0.8223    0.1684
    0.6073    0.4949    0.2980    0.8739    0.9885    0.9114    0.8611
    0.8898    0.7615    0.9958    0.4896    0.0338    0.1472    0.3266
    0.4907    0.6670    0.5544    0.6063    0.8595    0.3049    0.3252
    0.3135    0.9781    0.6561    0.7177    0.5286    0.7799    0.4002
    0.7621    0.1171    0.9453    0.1400    0.9755    0.4872    0.7635
    0.9545    0.8693    0.2246    0.5831    0.8772    0.5492    0.1641
    0.6459    0.5679    0.9815    0.1950    0.1613    0.8782    0.6883
    0.4853    0.1202    0.1706    0.0633    0.3534    0.9883    0.6433
    0.4382    0.9703    0.9411    0.0639    0.0580    0.0192    0.8214
    0.1864    0.8400    0.9570    0.9399    0.4441    0.3513    0.3785
    0.4431    0.0623    0.1750    0.5202    0.4411    0.5346    0.1119
    0.4881    0.2781    0.0543    0.1501    0.3267    0.7478    0.8595
    0.8611    0.4096    0.2682    0.6466    0.9144    0.9700    0.7132
    0.7165    0.6268    0.5460    0.5838    0.4946    0.6951    0.5750
    0.6203    0.9191    0.7752    0.3123    0.7102    0.2733    0.7411
    0.0898    0.4152    0.6038    0.6721    0.6646    0.9511    0.7537
    0.1118    0.7115    0.3161    0.3971    0.8318    0.9077    0.5551
    0.5756    0.9709    0.4334    0.2195    0.2580    0.4574    0.8009
    0.4617    0.4355    0.8428    0.2408    0.7692    0.7332    0.6703
    0.5454    0.6354    0.6261    0.3864    0.4106    0.5582    0.5351
    0.0380    0.9016    0.2725    0.0335    0.0557    0.9939    0.6859
    0.5793    0.8716    0.5145    0.3467    0.8706    0.3893    0.9552
    0.6290    0.1427    0.8884    0.5520    0.9723    0.8817    0.6278
    0.4819    0.2006    0.1743    0.5584    0.1170    0.8933    0.8191
    0.1605    0.6209    0.8201    0.0668    0.5083    0.3860    0.1890
    0.7544    0.7750    0.1812    0.5819    0.7556    0.7276    0.7515
    0.7935    0.2468    0.0973    0.4759    0.1100    0.9126    0.2216
    0.2914    0.3695    0.0313    0.6619    0.0339    0.9041    0.4164
    0.5076    0.3411    0.0102    0.7861    0.4411    0.0815    0.7909
    0.2380    0.4564    0.9674    0.1900    0.1298    0.0333    0.4000
    0.1927    0.1708    0.8880    0.9615    0.9716    0.5724    0.0451
    0.8087    0.7456    0.0497    0.5351    0.9402    0.0093    0.2010
    0.0667    0.0980    0.6702    0.9145    0.9331    0.1983    0.0429

koniec tablicy

Funkcja fprint

help fprintf
 FPRINTF Write formatted data to text file.
    FPRINTF(FID, FORMAT, A, ...) applies the FORMAT to all elements of array A and
    any additional array arguments in column order, and writes the data to a text
    file.  FID is an integer file identifier.  Obtain FID from FOPEN, or set it to 1
    (for standard output, the screen) or 2 (standard error). FPRINTF uses the
    encoding scheme specified in the call to FOPEN.
 
    FPRINTF(FORMAT, A, ...) formats data and displays the results on the screen.
 
    COUNT = FPRINTF(...) returns the number of bytes that FPRINTF writes.
 
    FORMAT is a character vector that describes the format of the output fields, and
    can include combinations of the following:
 
       * Conversion specifications, which include a % character, a
         conversion character (such as d, i, o, u, x, f, e, g, c, or s), and optional
         flags, width, and precision fields.  For more details, type "doc fprintf" at
         the command prompt.
 
       * Literal text to print.
 
       * Escape characters, including:
             \b     Backspace            ''   Single quotation mark
             \f     Form feed            %%   Percent character
             \n     New line             \\   Backslash
             \r     Carriage return      \xN  Hexadecimal number N
             \t     Horizontal tab       \N   Octal number N
         For most cases, \n is sufficient for a single line break. However, if you
         are creating a file for use with Microsoft Notepad, specify a combination of
         \r\n to move to a new line.
 
    Notes:
 
    If you apply an integer or text conversion to a numeric value that contains a
    fraction, MATLAB overrides the specified conversion, and uses %e.
 
    Numeric conversions print only the real component of complex numbers.
 
    Example: Create a text file called exp.txt containing a short table of the
    exponential function.
 
        x = 0:.1:1;
        y = [x; exp(x)];
        fid = fopen('exp.txt','w');
        fprintf(fid,'%6.2f  %12.8f\n',y);
        fclose(fid);
 
    Examine the contents of exp.txt:
 
        type exp.txt
 
    MATLAB returns:
           0.00    1.00000000
           0.10    1.10517092
                ...
           1.00    2.71828183
 
    See also FOPEN, FCLOSE, FSCANF, FREAD, FWRITE, SPRINTF, DISP.

    Reference page in Doc Center
       doc fprintf

    Other functions named fprintf

       distributed/fprintf    icinterface/fprintf    serial/fprintf
       gpuArray/fprintf

fprintf('Wynik: %8.3f \n', 27.66790)
Wynik:   27.668 
fprintf('Wynik: %08.3f \n', 27.66790)
Wynik: 0027.668 
fprintf('Wynik: %08.3f \n', -27.66790)
Wynik: -027.668 
fprintf('Wynik: %8.0f \n', -27.66790)
Wynik:      -28 
fprintf('Wynik: %12.3e \n', -27.66790)
Wynik:   -2.767e+01 
fprintf('Wynik: %8.2e \n', -27.66790)
Wynik: -2.77e+01 
fprintf('Wynik: %8.2e \n', 27.66790)
Wynik: 2.77e+01 
fprintf('Wynik: %8.0e \n', -27.66790)
Wynik:   -3e+01 
fprintf('Wynik: %08.0e \n', -27.66790)
Wynik: -003e+01 
fprintf('Wynik:  %08.0e \n', rand(3,4))
Wynik:  0006e-01 
Wynik:  0003e-01 
Wynik:  0004e-01 
Wynik:  0002e-01 
Wynik:  0009e-01 
Wynik:  0003e-01 
Wynik:  0002e-01 
Wynik:  0008e-01 
Wynik:  0002e-02 
Wynik:  0004e-02 
Wynik:  0005e-01 
Wynik:  0009e-01 

Inne przykłady

fprintf('Wartość całkowita wynosi %3d a zmienno-przecinkowa %6.2f\n', ...
    5, 4.9)
Wartość całkowita wynosi   5 a zmienno-przecinkowa   4.90
fprintf('Liczba całkowita wynosi xx%5dxx i xx%-5dxx\n',3,3)
Liczba całkowita wynosi xx    3xx i xx3    xx
fprintf('Nasz łańcuch to %s lub %.4s\n', 'obcięcie', 'obcięcie')
Nasz łańcuch to obcięcie lub obci
fprintf('Wypróbuj to: tabulator\t cudzysłów '' slash \\ \n')
Wypróbuj to: tabulator	 cudzysłów ' slash \ 

Wyświetlanie wektorów

wektor = 2:5
fprintf('Element wektora: %d', wektor)
wektor =

     2     3     4     5

Element wektora: 2Element wektora: 3Element wektora: 4Element wektora: 5
fprintf('\n', wektor)
fprintf('Element wektora: %d\n', wektor)
Element wektora: 2
Element wektora: 3
Element wektora: 4
Element wektora: 5

Wyświetlanie macierzy

mat = [1 2 3; 4 5 6]
fprintf('%d\n',mat)
mat =

     1     2     3
     4     5     6

1
4
2
5
3
6
mat
fprintf('%d %d %d\n',mat)
mat =

     1     2     3
     4     5     6

1 4 2
5 3 6
mat
fprintf('%d %d %d\n',mat')
mat =

     1     2     3
     4     5     6

1 2 3
4 5 6

Przykład prostego skryptu

type script1
script1
radius = 5
area = pi * (radius^2)

radius =

     5


area =

   78.5398

Dokumentacja

type script1a
% Skrypt "script1a.m" wyznacza powierzchnię koła
% Przypisz zmiennej r wartośc promienia
radius = 5 %
% Wyznacz wartość pola
area = pi * (radius^2)
help script1a
  Skrypt "script1a.m" wyznacza powierzchnię koła
  Przypisz zmiennej r wartośc promienia

Wykorzystanie funkcji dla operacji we/wy

type script1b
% script1b % wywołanie skrypu zakomentowane z powodu funkcji input
% Ten program wyznacza powierzchnię koła
% Program prosi użytkownika o podanie wartoci promienia koła
 
% Zachęta dla użytkownika do podania wartości promienia i pobranie wartości
% promienia
radius = input('Podaj wartość promienia: ');
% Wyznaczenie powierzchni koła
area = pi * (radius^2);
% Wyświetlenie wyniku w postaci pełnego zdania
fprintf('Pole powierzchni koła o promieniu %.2f wynosi %.2f\n', radius, area)

Skrypty - przykłady tworzenia i dostosowywanie wykresów 2D

help graph2d
  Two dimensional graphs.
  
  Elementary X-Y graphs.
    plot      - Linear plot.
    loglog    - Log-log scale plot.
    semilogx  - Semi-log scale plot.
    semilogy  - Semi-log scale plot.
    polar     - Polar coordinate plot.
    plotyy    - Graphs with y tick labels on the left and right.
 
  Axis control.
    axis       - Control axis scaling and appearance.
    zoom       - Zoom in and out on a 2-D plot.
    grid       - Grid lines.
    box        - Axis box.
    rbbox      - Rubberband box.
    hold       - Hold current graph.
    axes       - Create axes in arbitrary positions.
    subplot    - Create axes in tiled positions.
 
  Graph annotation.
    plotedit  - Tools for editing and annotating plots.
    title     - Graph title.
    xlabel    - X-axis label.
    ylabel    - Y-axis label. 
    texlabel  - Produces the TeX format from a character string.
    text      - Text annotation.
    gtext     - Place text with mouse.
 
  Hardcopy and printing.
    print      - Print graph or Simulink system; or save graph to MATLAB file.
    printopt   - Printer defaults.
    orient     - Set paper orientation. 
 
  See also GRAPH3D, SPECGRAPH.

type plotonepoint
% This is a really simple plot of just one point!

% Create coordinate variables and plot a red '*'
x = 11;
y = 48;
plot(x,y,'r*')

% Change the axes and label them
axis([9 12 35 55])
xlabel('Time')
ylabel('Temperature')

% Put a title on the plot
title('Time and Temp')

plotonepoint
axis([x-2 x+2 y-5 y+5])
x = 1:6;
y = [1 5 3 9 11 8];
figure
plot(x,y)
figure
plot(y)
close all
clear all
type plot2figs
% This creates 2 different plots, in 2 different
%  figure windows, to demonstrate some plot features

clf  
x = 1:5;  % Not necessary
y1 = [2 11 6 9 3];
y2 = [4 5 8 6 2];
% Put a bar chart in Figure 1
figure(1)
bar(x,y1)
% Put plots using different y values on one plot
% with a legend
figure(2)
plot(x,y1,'k')
hold on
plot(x,y2,'ko')
grid on
legend('y1','y2')
hold off
plot2figs
type sincos
%This program plots sin(x) and cos(x) in the same figure window
%  for values of x ranging from 0 to 2*pi

clf 
x = 0: 2*pi/40: 2*pi;
y = sin(x);
plot(x,y,'ro')
hold on
y = cos(x);
plot(x,y,'b+')
legend('sin', 'cos')
title('sin and cos on one graph')
sincos
type subplottypes
% Skrypt wykorzytstuje funkcję subplot w celu demonstacji różnych wykresów
% 2D

close all
figure
year = 2016:2020;
pop = [0.9 1.4 1.7 1.3 1.8];
subplot(2,2,1)
plot(year, pop)
title('plot')
xlabel('Rok')
ylabel('Populacja [mln]')
subplot(2,2,2)
bar(year, pop)
title('bar')
xlabel('Rok')
ylabel('Populacja [mln]')
subplot(2,2,3)
area(year, pop)
title('area')
xlabel('Rok')
ylabel('Populacja [mln]')
subplot(2,2,4)
stem(year, pop)
title('stem')
xlabel('Rok')
ylabel('Populacja [mln]')
subplottypes
type barwidths
% Skrypt deomstruje dopasowanie szerokości elementów wykresu słupkowego

figure
year = 2016:2020;
pop = [0.9 1.4 1.7 1.3 1.8];
i=1;
subplot(1,4,i)
barh(year, pop, 0.4*+i*0.2)
title('bar')
ylabel('Rok')
xlabel('Populacja [mln]')
i=i+1;
subplot(1,4,i)
barh(year, pop, 0.4*+i*0.2)
title('bar')
ylabel('Rok')
xlabel('Populacja [mln]')
i=i+1;
subplot(1,4,i)
barh(year, pop, 0.4*+i*0.2)
title('bar')
ylabel('Rok')
xlabel('Populacja [mln]')
i=i+1;
subplot(1,4,i)
barh(year, pop, 0.4*+i*0.2)
title('bar')
ylabel('Rok')
xlabel('Populacja [mln]')
barwidths
help semilogy
 SEMILOGY Semi-log scale plot.
    SEMILOGY(...) is the same as PLOT(...), except a
    logarithmic (base 10) scale is used for the Y-axis.
 
    See also PLOT, SEMILOGX, LOGLOG.

    Reference page in Doc Center
       doc semilogy

    Other functions named semilogy

       frd/semilogy

subplot(1,2,1)
plot(logspace(1,10))
title('plot')
subplot(1,2,2)
semilogy(logspace(1,10))
title('semilogy')

Skrypty - przykłady tworzenia i dostosowywanie wykresów 3D

help graph3d
  Three dimensional graphs.
  
  Elementary 3-D plots.
    plot3      - Plot lines and points in 3-D space.
    mesh       - 3-D mesh surface.
    surf       - 3-D colored surface.
    fill3      - Filled 3-D polygons.
   
  Color control.
    colormap   - Color look-up table.
    caxis      - Pseudocolor axis scaling.
    shading    - Color shading mode.
    hidden     - Mesh hidden line removal mode.
    brighten   - Brighten or darken color map.
    colordef   - Set color defaults.
    graymon    - Set graphics defaults for gray-scale monitors.
    cmpermute  - Rearrange colors in colormap.
    cmunique   - Eliminate unneeded colors in colormap of indexed image.
    imapprox   - Approximate indexed image by one with fewer colors.
 
  Lighting.
    surfl      - 3-D shaded surface with lighting.
    lighting   - Lighting mode.
    material   - Material reflectance mode.
    specular   - Specular reflectance.
    diffuse    - Diffuse reflectance.
    surfnorm   - Surface normals.
 
  Color maps.
    parula     - Blue-green-orange-yellow color map
    hsv        - Hue-saturation-value color map.
    hot        - Black-red-yellow-white color map.
    gray       - Linear gray-scale color map.
    bone       - Gray-scale with tinge of blue color map.
    copper     - Linear copper-tone color map.
    pink       - Pastel shades of pink color map.
    white      - All white color map.
    flag       - Alternating red, white, blue, and black color map.
    lines      - Color map with the line colors.
    colorcube  - Enhanced color-cube color map.
    vga        - Windows colormap for 16 colors.
    jet        - Variant of HSV.
    prism      - Prism color map.
    cool       - Shades of cyan and magenta color map.
    autumn     - Shades of red and yellow color map.
    spring     - Shades of magenta and yellow color map.
    winter     - Shades of blue and green color map.
    summer     - Shades of green and yellow color map.
 
  Transparency.
    alpha      - Transparency (alpha) mode.
    alphamap   - Transparency (alpha) look-up table.
    alim       - Transparency (alpha) scaling
 
  Axis control.
    axis       - Control axis scaling and appearance.
    zoom       - Zoom in and out on a 2-D plot.
    grid       - Grid lines.
    box        - Axis box.
    hold       - Hold current graph.
    axes       - Create axes in arbitrary positions.
    subplot    - Create axes in tiled positions.
    daspect    - Data aspect ratio.
    pbaspect   - Plot box aspect ratio.
    xlim       - X limits.
    ylim       - Y limits.
    zlim       - Z limits.
 
  Viewpoint control.
    view       - 3-D graph viewpoint specification.
    viewmtx    - View transformation matrix.
    rotate3d   - Interactively rotate view of 3-D plot.
 
  Camera control.
    campos     - Camera position.
    camtarget  - Camera target.
    camva      - Camera view angle.
    camup      - Camera up vector.
    camproj    - Camera projection.
 
  High level camera control.
    camorbit   - Orbit camera.
    campan     - Pan camera.
    camdolly   - Dolly camera.
    camzoom    - Zoom camera.
    camroll    - Roll camera.
    camlookat  - Move camera and target to view specified objects.
    cameratoolbar - Interactively manipulate camera.
 
  High level light control.
    camlight   - Creates or sets position of a light.
    lightangle - Spherical position of a light.
 
  Graph annotation.
    title      - Graph title.
    xlabel     - X-axis label.
    ylabel     - Y-axis label.
    zlabel     - Z-axis label.
    text       - Text annotation.
    gtext      - Mouse placement of text.
    plotedit   - Experimental graph editing and annotation tools.
 
  Hardcopy and printing.
    print      - Print graph or Simulink system; or save graph to MATLAB file.
    printopt   - Printer defaults.
    orient     - Set paper orientation. 
 
  See also GRAPH2D, SPECGRAPH.

close
x = 1:5;
y = [0 -2 4 11 3];
z = 2:2:10;
plot3(x,y,z,'-k*');
grid
xlabel('x')
ylabel('y')
zlabel('z')
title('3D plot')

Dostosowywanie wykresów poprzez zmianę właściwości obiektów

close all
f = figure
f = 

  Figure (1) with properties:

      Number: 1
        Name: ''
       Color: [0.9400 0.9400 0.9400]
    Position: [680 558 560 420]
       Units: 'pixels'

  Use GET to show all properties

get(f)
fProp = get(f)
                 Alphamap: [1×64 double]
             BeingDeleted: 'off'
               BusyAction: 'queue'
            ButtonDownFcn: ''
                 Children: [0×0 GraphicsPlaceholder]
                 Clipping: 'on'
          CloseRequestFcn: 'closereq'
                    Color: [0.9400 0.9400 0.9400]
                 Colormap: [64×3 double]
                CreateFcn: ''
              CurrentAxes: [0×0 GraphicsPlaceholder]
         CurrentCharacter: ''
            CurrentObject: [0×0 GraphicsPlaceholder]
             CurrentPoint: [0 0]
                DeleteFcn: ''
             DockControls: 'on'
                 FileName: ''
        GraphicsSmoothing: 'on'
         HandleVisibility: 'on'
            InnerPosition: [680 558 560 420]
            IntegerHandle: 'on'
            Interruptible: 'on'
           InvertHardcopy: 'on'
              KeyPressFcn: ''
            KeyReleaseFcn: ''
                  MenuBar: 'figure'
                     Name: ''
                 NextPlot: 'add'
                   Number: 1
              NumberTitle: 'on'
            OuterPosition: [672 550 576 512]
         PaperOrientation: 'portrait'
            PaperPosition: [3.0917 9.2937 14.8167 11.1125]
        PaperPositionMode: 'auto'
                PaperSize: [21.0000 29.7000]
                PaperType: 'A4'
               PaperUnits: 'centimeters'
                   Parent: [1×1 Root]
                  Pointer: 'arrow'
        PointerShapeCData: [16×16 double]
      PointerShapeHotSpot: [1 1]
                 Position: [680 558 560 420]
                 Renderer: 'opengl'
             RendererMode: 'auto'
                   Resize: 'on'
            SelectionType: 'normal'
           SizeChangedFcn: ''
                      Tag: ''
                  ToolBar: 'auto'
                     Type: 'figure'
            UIContextMenu: [0×0 GraphicsPlaceholder]
                    Units: 'pixels'
                 UserData: []
                  Visible: 'on'
      WindowButtonDownFcn: ''
    WindowButtonMotionFcn: ''
        WindowButtonUpFcn: ''
        WindowKeyPressFcn: ''
      WindowKeyReleaseFcn: ''
     WindowScrollWheelFcn: ''
              WindowStyle: 'normal'


fProp = 

  struct with fields:

                 Position: [680 558 560 420]
            OuterPosition: [672 550 576 512]
            InnerPosition: [680 558 560 420]
                    Units: 'pixels'
                 Renderer: 'opengl'
             RendererMode: 'auto'
                  Visible: 'on'
                    Color: [0.9400 0.9400 0.9400]
          CloseRequestFcn: 'closereq'
              CurrentAxes: [0×0 GraphicsPlaceholder]
         CurrentCharacter: ''
            CurrentObject: [0×0 GraphicsPlaceholder]
             CurrentPoint: [0 0]
            SelectionType: 'normal'
           SizeChangedFcn: ''
                 FileName: ''
            IntegerHandle: 'on'
                 NextPlot: 'add'
                 Alphamap: [1×64 double]
                 Colormap: [64×3 double]
        GraphicsSmoothing: 'on'
      WindowButtonDownFcn: ''
        WindowButtonUpFcn: ''
    WindowButtonMotionFcn: ''
     WindowScrollWheelFcn: ''
        WindowKeyPressFcn: ''
      WindowKeyReleaseFcn: ''
                  MenuBar: 'figure'
                  ToolBar: 'auto'
                  Pointer: 'arrow'
        PointerShapeCData: [16×16 double]
      PointerShapeHotSpot: [1 1]
                     Name: ''
              NumberTitle: 'on'
                   Number: 1
            UIContextMenu: [0×0 GraphicsPlaceholder]
            ButtonDownFcn: ''
               BusyAction: 'queue'
             BeingDeleted: 'off'
            Interruptible: 'on'
                CreateFcn: ''
                DeleteFcn: ''
                     Type: 'figure'
                      Tag: ''
                 UserData: []
                 Clipping: 'on'
              WindowStyle: 'normal'
             DockControls: 'on'
                   Resize: 'on'
            PaperPosition: [3.0917 9.2937 14.8167 11.1125]
        PaperPositionMode: 'auto'
                PaperSize: [21.0000 29.7000]
                PaperType: 'A4'
               PaperUnits: 'centimeters'
           InvertHardcopy: 'on'
         PaperOrientation: 'portrait'
              KeyPressFcn: ''
            KeyReleaseFcn: ''
                 Children: [0×0 GraphicsPlaceholder]
                   Parent: [1×1 Root]
         HandleVisibility: 'on'

f.Name
fPropName = get(f,'Name')
ans =

  0×0 empty char array


fPropName =

  0×0 empty char array

f.Name = 'Nazwa okna graficznego'
f = 

  Figure (1: Nazwa okna graficznego) with properties:

      Number: 1
        Name: 'Nazwa okna graficznego'
       Color: [0.9400 0.9400 0.9400]
    Position: [680 558 560 420]
       Units: 'pixels'

  Use GET to show all properties

Uchwyty do obiekt ow tworzonych przez funkcje graficzne

x = -2*pi:1/5:2*pi;
y = sin(x);
hl = plot(x,y)
hl = 

  Line with properties:

              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [1×63 double]
              YData: [1×63 double]
              ZData: [1×0 double]

  Use GET to show all properties

axhan = hl.Parent
axhan = 

  Axes with properties:

             XLim: [-8 8]
             YLim: [-1 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Use GET to show all properties

hl.LineWidth = 5
hl = 

  Line with properties:

              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 5
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [1×63 double]
              YData: [1×63 double]
              ZData: [1×0 double]

  Use GET to show all properties

Funkcje gcf, gca, ...

clear all
x = -pi:0.1:pi
f1 = figure(1);
p1 = plot(x,sin(x));
f2 = figure(2);
p2 = plot(x,cos(x),'Color',[0 1 1]);
x =

  Columns 1 through 7

   -3.1416   -3.0416   -2.9416   -2.8416   -2.7416   -2.6416   -2.5416

  Columns 8 through 14

   -2.4416   -2.3416   -2.2416   -2.1416   -2.0416   -1.9416   -1.8416

  Columns 15 through 21

   -1.7416   -1.6416   -1.5416   -1.4416   -1.3416   -1.2416   -1.1416

  Columns 22 through 28

   -1.0416   -0.9416   -0.8416   -0.7416   -0.6416   -0.5416   -0.4416

  Columns 29 through 35

   -0.3416   -0.2416   -0.1416   -0.0416    0.0584    0.1584    0.2584

  Columns 36 through 42

    0.3584    0.4584    0.5584    0.6584    0.7584    0.8584    0.9584

  Columns 43 through 49

    1.0584    1.1584    1.2584    1.3584    1.4584    1.5584    1.6584

  Columns 50 through 56

    1.7584    1.8584    1.9584    2.0584    2.1584    2.2584    2.3584

  Columns 57 through 63

    2.4584    2.5584    2.6584    2.7584    2.8584    2.9584    3.0584

curfig = gcf
curfig.Children
curfig.Children == gca
curfig.Children.Children
curfig = 

  Figure (2) with properties:

      Number: 2
        Name: ''
       Color: [0.9400 0.9400 0.9400]
    Position: [680 558 560 420]
       Units: 'pixels'

  Use GET to show all properties


ans = 

  Axes with properties:

             XLim: [-4 4]
             YLim: [-1 1]
           XScale: 'linear'
           YScale: 'linear'
    GridLineStyle: '-'
         Position: [0.1300 0.1100 0.7750 0.8150]
            Units: 'normalized'

  Use GET to show all properties


ans =

  logical

   1


ans = 

  Line with properties:

              Color: [0 1 1]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [1×63 double]
              YData: [1×63 double]
              ZData: [1×0 double]

  Use GET to show all properties