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...

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...

Welding-LAP JOINT

Ex. No :                                                                              Date : LAP JOINT Aim To join the given two work pieces as a lap joint by arc welding. Material used Mild Steel plates. Tools required Welding power supply  Flat file Welding rod Chipping hammer Electrode holder Wire brush Gloves and apron Earthing clamps Shield and goggles Procedure The given workpieces are thoroughly cleaned, i.e. rust, scales are removed and the  edges are filed. The electrode is held in an electrode holder and ground clamp is clamped to the  welding plates and the power is supplied. The workpieces are positioned on the table to form a “Lab joint”. The tag weld is done on the both the ends of joining plates to avoid the m...

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...

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...

Welding VIVA question and answers

VIVA QUESTIONS : Q1: Define welding? Ans:  Welding is a fabrication process that joins two or more materials, typically metals or thermoplastics, by melting and fusing them together using heat or pressure. Q2: What is the typical thickness of MS Plate used in general welding workshop experiments? Ans:  The thickness of the MS (Mild Steel) plate used in general welding workshop experiments can vary depending on the specific requirements of the experiment. However, commonly used thicknesses range from 3 mm to 12 mm. Q3: What is the common job material used in welding experiments? Ans:  The common job material used in welding experiments is mild steel. It is widely available, affordable, and relatively easy to work with, making it suitable for various welding applications and practice. Q4: What is the main function of an electrode in welding? Ans:  The main function of an electrode in welding is to carry the electric current necessary for the welding process and to ...

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 ...

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.

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...

Welding-TEE FILLET JOINT

Ex. No :                                                                                 Date : TEE FILLET JOINT Aim To join the given two work pieces as a ‘Tee fillet joint’ by arc Welding. Material used Mild steel plates. Tools required • Welding power supply • Flat file • Welding rod • Chipping hammer • Electrode holder • Wire brush • Gloves and apron  • Earthing clamps • Shield and goggles Procedure The given workpieces are thoroughly cleaned, i.e. rust, scales are removed and the  edges are filed. The electrode is held in an electrode holder and ground clamp is clamped to the  welding plates and the power is supplied. The workpieces are positioned on the table to form a “Tee fillet joint”. The tag weld is done on the bo...

Search This Blog