Question

how to modify code in matlab to have a calculation linked to various names? for example...

how to modify code in matlab to have a calculation linked to various names?

for example if katie weighs 120 lbs and her density is 2.2, but abby weighs 140 lbs and her density is 3.4

the output i want is volume

how do i associate weight and density to a name? so if the user were to input “katie” matlab would know that the weight and density are 120 and 2.2

Homework Answers

Answer #1

USE ORDERED ARRAYS/CELLS FOR THE NAMES, WEIGHTS AND DENSITIES THEN COMPARE THE INPUT (NAME) WITH ALL THE NAMES, IF A MATCH IS FOUND, LOOK UP THE CORRESPONDING VALUES FOR WEIGHT AND DENSITY

'

strcmpi - compares 2 strings (not case sensitive) and returns true (1) if the two strings are equal, false (0) otherwise

Consider the matlab program below:

'

'

____________________________________

clc,clear

%%
% define the variables in [ordered] arrays/cells
names = {'katie','abby'}; % names
w = [120 140]; % weight
d = [2.2,3.4]; % density

%%
% get name from input
name = input('Enter name: ','s');

%%
% search for the name entered and if found, look up the weight and density
for i=1:length(names) % check all names
if(strcmpi(names(i),name)) % compare the name with all names
% if found, do something with the weight and density
weight = w(i)
density = d(i)
volume = weight/density
end
end


------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java please. Need to use a linked list only. Many people have used pulling petals off...
Java please. Need to use a linked list only. Many people have used pulling petals off roses and tossing them in the air to determine if someone loves them or not. Your sister wants to use roses to determine which one of several suitors she will let take her to the prom. A linked list can be used to represent the prom date suitors. Write a program to simulate her decision and determine her prom date. The simulation will work...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT