Filter löschen
Filter löschen

Making numbers equal to a definite value

1 Ansicht (letzte 30 Tage)
MSA
MSA am 13 Jun. 2020
Kommentiert: Walter Roberson am 14 Jun. 2020
I have an array of numbers such as- 95, 48, 30 and 51. I need to make these equal to 50 using different factors. How can I do that using loop without doing it manually? Need to know the multiplication factors that making all these numbers equal to 50. Don't want any definite answers. Just need a heads up in the right direction.

Akzeptierte Antwort

madhan ravi
madhan ravi am 13 Jun. 2020
Bearbeitet: madhan ravi am 13 Jun. 2020
array(ismember(array,[95, 48, 30, 51])) = 50
P.S: Didn’t realise it was a homework question. However it requires a loop. Mohammed come up with a solution using loop to get your homework done as by the requirements.
  4 Kommentare
John D'Errico
John D'Errico am 14 Jun. 2020
Oh, I don't think your answer will qualify as a solution, even done in a loop. For that matter, mine is pretty worthless too, in terms of the homework requirements. Such is life.
James Tursa
James Tursa am 14 Jun. 2020
Not completely worthless ... it made me laugh!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

John D'Errico
John D'Errico am 14 Jun. 2020
Bearbeitet: John D'Errico am 14 Jun. 2020
This is your homework assignment, posted with no effort made. Unfortunately, Madhan was sleepy and answered it, so it cannot be closed. His answer is irrelevant - useless in context. But if I told you enough of a hint to direct you in the correct direction, I might as well do the homework for you. Seriously, this is not a difficult problem. So now you need to do some thinking. YOURSELF.
Here is a clue, that in fact should be far more than you need.
When you don't know how to solve a problem in MATLAB, one idea is to just look through some of the functions in MATLAB. Read the help. Are any of them ones that might be helpful? What is it you want to do? If you have some keyword that would be on target, then the command lookfor will help greatly.
For example, suppose I wanted to learn how to do a plot in MATLAB? I might try this at the command line.
>> lookfor plot
Admittedly, that will generate a HUGE amount of function names. But some of them might give me an idea. I'll see things like this:
geoscatter - Geographic scatter plot
histogram - Plots a Histogram.
histogram2 - Plots a bivariate histogram.
plot - Linear plot.
scatter - Scatter plot.
So one line per function. Do any of them help? Then I might be able to refine my search.
Look. Think. Read. Then look again.
Another trick, if I wanted to learn about plotting in MATLAB, is to look for where the plot function lives.
>> which plot
built-in (/Applications/MATLAB_R2019b.app/toolbox/matlab/graph2d/plot)
That tells me plot lives in the graph2d directory. If you ask for help about an entire directory in MATLAB, it gives you just that. So now I might try this:
>> help grap2d
Now I would see things like this:
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.
... (and more)
Again, I would see lists of functions. Some of them might be useful. So now I would start reading the help for any function that might be on-target.
Yes, that is if I wanted to learn about plotting in MATLAB. What do YOU need to do here? What are you trying to find? What aspect of those numbers do you need to know about? Again, it is time for you to make an effort. The tools are in there. But only if you look for them will you learn something. And that is the purpose of doing homework. Not for us to do it for you.
  3 Kommentare
MSA
MSA am 14 Jun. 2020
Bearbeitet: Walter Roberson am 14 Jun. 2020
Thanks a lot for your help. I have tried to solve this problem. Hope, you would give some suggestion on my solution.
clc
clear all
close all
x= [95 48 30 51]
y=numel(x)
x1=50
for i=1:y
if x==50
x1=50
x2=1
else
x1=50
x3=x1./x
x2=x3
end
end
Walter Roberson
Walter Roberson am 14 Jun. 2020
What is the required output?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by