Skip to main content

How to separate given vector into different conditions using MATLAB

Also Read

Set even values zero and other multiplied by 3

clear all
clc
A= [3 15 27; 6 18 30; 9 21 33; 12 24 36]; % Vector declaration
disp(A); %Display Vector before performing operation
for i = 1 : size(A)
for k = 1: 3
if rem(A(i,k), 2) == 0 %If number is even, then set it to 1
A(i, k) = 1;
else
A(i,k) = A(i,k)*3; %else multiple by 3
end
end
end
disp(A) %Display vector after operation

Set the positive values of x to zero


x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
disp(x); %Display Vector before performing operation
for i = 1 : size(x, 2)
if x(1, i) > 0 %if number is greater than 0, then set it to 0
x(1, i) = 0;
end
end
disp(x);   %Display vector after operation

Set values that are multiples of 3 to 3



x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
disp(x); %Display Vector before performing operation
for i = 1 : size(x, 2)
if rem(x(1, i), 3) == 0 %If number is multiple of 3, then set it to 3
x(1, i) = 3;
end
end
disp(x);   %Display vector after operation

Multiply the even values of x by 7



x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
disp(x); %Display Vector before performing operation
for i = 1 : size(x, 2)
if rem(x(1, i), 2) == 0 %if number is even, then multiply it by 7
x(1, i) = x(1, i)*7;
end
end
disp(x);   %Display vector after operation

Extract the values of x that are greater than 5 into a vector called y




x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
y = []; %Create empty vector to store result
j = 1;
for i = 1 : size(x, 2)
if x(1, i) > 5 %if number is greater than 5, then store it in vector y
y(1, j) = x(1, i);
j = j + 1;
end
end
disp('the new y matrix is:')
disp(y);

Select that larger value of x and print it into vector called z



x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
y = []; %Create empty vector to store result
y = max(x)

disp('the new y matrix is:')
disp(y)

Set the values in x that are less than the mean to zero




x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
disp(x); %Display Vector before performing operation
sum = 0;
for i = 1 : size(x, 2) %Get the sum of all numbers
sum = sum + size(1, i);
end
mean = sum / size(x, 2); %Calculate Mean
for i = 1 : size(x, 2)
if x(1, i) < mean %Set all the numbers that are less than mean to 0
x(1, i) = 0;
end
end

disp(x)   %Display vector after operation

Set the values in x that are above the mean to their difference from the mean



x= [6 20 8 13 -5 -4 0 12 7 9 3 2]; % Vector declaration
disp(x); %Display Vector before performing operation
sum = 0;
for i = 1 : size(x, 2) %Sum of all the numbers
sum = sum + size(1, i);
end

mean = sum / size(x, 2);    %Calculate Mean

for i = 1 : size(x, 2)
if x(1, i) > mean   %Set all the numbers that are greater than mean to 0
x(1, i) = 0;
end
end

disp(x);   %Display vector after operation


Comments

Recent posts

Isometric drawings for practice in AutoCAD

What is Isometric Drawing? Isometric drawing is a method of visually representing three-dimensional objects in two dimensions. It allows for a clear and comprehensive depiction of complex structures by keeping the scale consistent and eliminating distortion. Isometric drawings use a 30-degree angle from the horizontal in all three axes (X, Y, and Z), creating a pseudo-3D effect where the height, width, and depth are equally foreshortened. Creating Isometric Drawings in AutoCAD AutoCAD provides tools and settings that make creating isometric drawings straightforward. Here’s a step-by-step guide: Step 1: Set Up Isometric Snap/Grid 1. Enable Isometric Snap/Grid:    - Type `SNAP` in the command line and press `Enter`.    - Type `Style` and press `Enter`.    - Choose `Isometric` and press `Enter`. 2. Switch Between Isoplanes:    - Type `F5` or `CTRL+E` to toggle between the top, right, and left isoplanes. Step 2: Draw Isometric Circles and Arcs 1. Isom...

Step by step procedure to insert 3rd Angle Projection symbol in Solidworks

Step 1: open solidworks drawing tool with default or your required sheet size. Then the object view in paper space. Step 2: 1. Click on Annotation tab and select "Note". 2. Then add the note at title block. 3. Then click on add symbol in properties manager. 4. Then click on add more symbols. Step 3: Check the symbol in symbol library categories. if you found the symbol then click on "OK" button. if you not found the 3rd angle projection in the symbol library categories then see the Step 4 in this page. Step 4: 1. Go to this file location from your computer by pasting the below in your windows explorer or browse from your computer or search "gtol.sym" and open the file location by using right clicking on the searchable file. C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2019\lang\english 2. Then copy the "gtol.sym" file then paste this file in anywhere you like. here i'm pasting this file in desktop > Solidworks > pr...

SINGLE ‘V’ BUTT JOINT

Experiment No.:                                                                                      Date: SINGLE ‘V’ BUTT JOINT Aim: To prepare a single ‘V’ Butt Joint as per dimensions given in the sketch. Material Required: Mild Steel plates: 80mm X 40mm X 6mm = 2 Nos Mild Steel electrode ¢ 3.15 mm Equipment required: A.C. Transformer with all welding accessories like Electrode holder, cables. Tool Required: Steel rule 300mm  Scriber 150mm Flat file 300mm Try square 200mm Flat Tong 450mm  Chipping hammer 200mm Ball peen hammer 750mm  Wire brush Welding screen Sequence of Operations: 1. Marking  2. Filing  3. Welding  4. Finishing Procedure: Take two Mild steel plates of size 80mm X 40mm X 6mm. Fix the wor...

sheet metal rectangular tray making

Aim :- To make a rectangular tray from a given metallic sheet. Tools Required MALLET Snip Stake STEEL RULE Ball peen HAMMER Straight EDGE RIVETS Scriber Procedure The given metal sheet is smoothed using mallet. The measurements of rectangular tray (tray development drawing) is drawn on the sheet with given dimensions using the scriber and steel rule. The sheet is cut as per the marked dimensions by straight snips. Fold or bend as per the given order using mallet and stake. Bending is done as per the given dimension using the stake and mallet. Rivet the folded sheet by using the given rivets and hammer. Safety Precautions Each cut you make exposes sharp edges and creates burrs that can slice a finger. Must Use Hand gloves when cutting the sheet. Metal waste also has hazardous edges. So...

SMITHY Shop Tools

Smithy (Forging) Shop Tools: Smith’s Forge or Hearth :  It is used for heating purpose during the forging operation .  The structure of hearth is made of cast iron or cast steel. It has four-legged support, an hearth known as bottom, a chimney along with hood. An opening is also provided on the rear side of the structure to supply the air into the furnace.The hearth is covered by fire bricks lining.For quenching purpose, a water tank is also provided in front side of forge. Air under pressure is supplied to the furnace by the blower. List of tools used in forging shop (1) Fullers (Pair is required) (2) Swages (Pair is required)  (3) Flatter (4) Set Hammer (5) Chisels (6) Punch and Drift  (7) Drifts Anvil:  The anvil forms a support for black smiths work when hammering. The body of the Anvil is made of mild steel with a tool steel face welded on the body but the beak or horn used for bending curve is not steel faced. The round hole in the Anvil called ...

Sheet metal Funnel making

Making a Funnel using metallic sheet Making a Funnel using metallic sheet Aim:- To make a funnel from a given (GI)metallic sheet. Tools Required:- MALLET, SNIP, STAKE, STEEL RULE, BALL PEEN HAMMER, STRAIGHT EDGE, RIVETS, SCRIBER Procedure:  The size of the given sheet metal is checked for its dimensions using a steel rule The required development of surface is being made on the white paper which is overlapped on the sheet metal. The marking is done on the sheet metal as per the development being done on the paper. Now using straight snips, unwanted materials are removed. Now fold and bend the workpiece to make the funnel shape and joint is made on the workpieces. Then using a groover, a locked grooved joint is made for about 5mm. Also, hemming is done in the bottom of the funnel. In between top face and bottom face, a butt joint is made using a solder. Finally, trimming and finishing operations are carried out. Safety Precautions:- Each cut you make exposes s...

step by step procedure to draw hook 2D drawing using AutoCAD

1. Create one vertical line and two horizontal lines like shown below according to dimensions. 2.Draw the circles at intersecting points like shown below with given dimensions. 3. Draw TTR (tangent tangent Radius) circles like shown below with given radius values. 4. Trim extra elements using " TR " command the final image be shown like below. 5. Now draw another reference lines and circles using TTR(tangent tangent Radius) circle according to given dimensions. 6. Now Trim the extra elements by using "TR" command. 7. Now dimension the elements using DIM command.

Coordinate systems in AutoCAD

World Coordinate System (WCS), User Coordinate System (UCS). There is 4 AutoCAD coordinates system you should know. Absolute coordinate system , Relative Rectangular coordinate system, Relative Polar coordinate system and Interactive system(Direct coordinate system). Absolute Coordinate system: Absolute Coordinates uses the Cartesian System to specify a position in the X, Y, and (if needed) Z axes to locate a point from the 0-X, 0-Y, and 0-Z (0,0,0) point. To locate a point using the Absolute Coordinate system, type the X-value, Y-value, and, if needed, the Z-value separated by commas (with no spaces). Syn: Enter LINE command: L [Enter] Start line at point A: 0,0 [Enter] End first line at point B: 2,2 [Enter] End of second line at point C: 2,3 [Enter] Examples shown bellow. Relative Rectangular Coordinate system: After first points entered, your next points can be entered by specifying the next coordinate compare/relative f...

TIN SMITHY & Sheet metal

TIN SMITHY Introduction : Many engineering and house articles such as boxes, cans, funnels, ducts etc. are made from a flat sheet of metal. The process being known as tin smithy. For this the development of the article is first drawn on the sheet metal, then cut and folded, to form the required shape of the article. Allowance should be given in the drawing stage for folding and bending. This allowance depends upon the radius of the bend and thickness of the sheet metal. Sheet Metal Materials : A variety of metals are used in a sheet metal shop such as galvanized Iron, black, Iron, tin, Stainless Steel, copper and Aluminium. Hand Tools : The common hand tools used in sheet metal work are steel, try square, Wire gauge, Scriber, Ball peen hammer, Nylon Mallet, Snips Divider, Stakes, Cutting plier and Soldering Iron. Here, the details of tools that are being equipped by our workshop purpose only are presented. Wire Gauge: The thickness of sheet is referred in numbers known ...

FACING, PLAIN TURNING AND STEP TURNING

Ex. No :                                                                                                          Date : FACING, PLAIN TURNING AND STEP TURNING Aim                       To perform turning, facing and chamfering on a cylindrical work piece. Material used                       Mild steel cylindrical rod. Tools required Lathe Three-jaw chuck Chuck key Vernier caliper Single-point cutting tool Procedure First loosen the jaw in the chuck key to position the work piece, and then tighten the  jaws. Fix the cutting tool in the toolpost. Switch on the lath...

Search This Blog