You Can See Contents of Any Variable by Entering The Name of The Variable
You Can See Contents of Any Variable by Entering The Name of The Variable
com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-
operations.htmlYou can see contents of any variable by entering the name of the
variable. :DATA
The clear function cleans up the workspace. You can use the clc clean up
the Command Window.
Dans matlab on a Command window,workspace and current folder
[ x y] deux colones ,une ligne
[x ;y] un colone deux lingne
y = 5:8
y =
5 6 7 8
x = 20:2:26
x =
20 22 24 26
linspace(first,last,number_of_elements)
Rand,zeros ,size
x=zeros(6,3) 6lingnes 3 colone des zeros
ARRAY :
x(idx) x(row,col)
When used as an index, the colon operator (:) specifies all the elements in that dimension. The
syntax
x = A(2,:)
creates a row vector containing all of the elements from the second row of A: density=data(:,2)
The colon operator can refer to a range of values. The following syntax creates a matrix
containing the first, second, and third rows of the matrix A. x = A(1:3,:)
The colon operator can refer to a range of values. The following syntax creates a matrix
containing the first, second, and third rows of the matrix A. x = A(1:3,:)attention le
petit et après le grand
A single range of index values can be used to reference a subset of vector elements. For exampl
x = v(3:end) returns a subset of vector v containing the elements from 3 to the end
6.1 Performing Array Operations on Vectors
This code sets up the interaction.
load datafile
density = data(:,2);
v1 = data(:,3);
v2 = data(:,4);
TASK
Add 1 to each element of v1 and store the result in a variable named r.
Mon essai: v1=v1+1; r=v1
WROOOONG
r=1+v1 juste
xMax = max(x)
The * operator performs matrix multiplication. So, if you use * to multiply two
equally sized vectors, since the inner dimensions do not agree, you will get an error
message.
z = [3 4] * [10 20]
Error using *
Incorrect dimensions for matrix multiplication.
z =
30 80
The maximum value of a vector and its corresponding index value can be
determined using the max function. The first output from the max function is the
maximum value of the input vector. When called with two outputs, the second
output is the index value. [xMax,idx] = max(x)
Exemple :
Try getting the index value of the minimum value in v2. Use this index to extract
from density:
Obtaining Help
Exemple :randi
density=data(:,2)
[~,ivMin]=min(v2)
densityMin=density(iMin)
https://fr.mathworks.com/help/matlab/ref/linespec.html
HOLD ON :
Enter the hold on command.
Then plot mass1 (y-axis) against sample (x-axis) with black (k) square (s) markers and no line.
hold on ;
plot(sample,mass1,"ks")
HOLD OFF : While the hold state is on, plots will continue to go on the same axes. To return to the
default plot behavior, where each plot gets its own axes, enter hold off.
When you plot a single vector by itself, MATLAB uses the vector values as the y-axis data and sets
the x-axis data to range from 1 to n (the number of elements in the vector).
exemple
Moor https://fr.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.line-
properties.html
TITLE
title("Plot Title")
LABEEEL
https://fr.mathworks.com/products/matlab/plot-gallery.html
LES TABLEAUX
https://fr.mathworks.com/help/matlab/ref/readtable.html
https://fr.mathworks.com/help/matlab/import_export/read-spreadsheet-data-into-table.html
LOGIC INDEXING
https://fr.mathworks.com/help/matlab/matlab_prog/array-comparison-with-relational-
operators.html
exemple
A < B
lt(A,B)
autre example
test =lt(pi,4)
test=1(logic 1 ou 0)
Ou simplement test = pi < 4
You can compare a vector or matrix to a single scalar value using relational operators. The result is a
logical array of the same size as the original array.
[5 10 15] > 12
ans =
0 0 1
You can use logical indexing to reassign values in an array. For example, if you wish to replace all
values in the array x that are equal to 999 with the value 1, use the following syntax.
x(x==999) = 1
exemple :
You can use the logical operators and (&) and or (|) to combine logical comparisons.
x = v1(v1>6 | v1<2)
Try getting the values in sample that are between 10 and 20.
x=sample(sample>10 & sample<20)
When this code is run, the loop body will be executed three times, as the loop counter (c)
progresses through the values 1:3 (1, 2, and 3).
14.1 Project - Stellar Motion
Projet2
Stellar Motion II