f

#### Some basic questions about MATLAB operation

```Hi, I have recently started using MATLAB for a DSP and a
Communication Theory class. I have some questions about how MATLAB
does some things.

1. To plot a graph, say a sinusoid, I always do this:
t=0:.1:10;
a=sin(t);
plot(t,a)
What does MATLAB do to generate the data for the points that are not
in increments of .1? for example sin(1.13)? Does it interpolate to
generate the graph? Is this sinusoid only valid for .1 increments? In
fact, a function in MATLAB is inherently discrete, but we use it to
model continuous functions (its 'domain' is actually only 101
samples)?

2. I'm having trouble mixing up the indices of the array (1..101 for
t matrix) and the actual values (t(1)=0 t(1)=0.1, etc.)I am doing a
lot of shifting of functions (such as f(x) = x -> f(x-2) = x-2)
and this is messing me up, I usually get the error, "indices must be
positive or logicals.." Mathematically, it makes sense to compute
f(x(1)-2) for x(1)=1, but it doesn't make sense in MATLAB to ask for
f(-1). This brings me to the question of what is a reasonable matrix
size for x. -100:.1:100 ? Does it depend on the precision you need?
Is there a 'convention' used to model functions?

3. I had a misconception that MATLAB was very close to mathematical
notation. In fact, you have to interpret a lot when using it, often
going back to the theory to make sure computations make sense. So am
I using it the 'right' way. Usually only crunching huge amounts of
numbers?

I know it's a lot to ask, but it would help me a lot to clear up my
mind so I can use the program more efficiently.

Thanks,

Luis.
``` 0 10/17/2004 4:11:24 AM comp.soft-sys.matlab  211265 articles. 25 followers. 2 Replies 1095 Views Similar Articles

[PageSpeed] 22

```Hi Luis,

1/ for any curve, Matlab use an interpolation to plot points that are
not in the abscissa vector ...

2/ to use a function, u have to put this in an M file, using this
syntax :

function result = f(x)

result = sin(x-pi/2);

and for x, you can have a double, a vector, a matrix ...
When u use the syntax f(-1) in the workspace MATLAB, without having
written your function in an M-File, f is a vector and -1 is the index
of the vector, and that's also impossible, that's the reason why it
gives u the message : "indices must be positive or logicals..".

With the M-File, u can now use in the workspace that :

v = [-pi:.1:pi];
y = f(v) and u get the values for each value of v with the function f
....

Yes, it depends on the precision u want for the plot !!!

Good luck, and have a good day ...

Jeje.
``` 0 10/17/2004 11:28:25 AM
```In article <eeed41d.-1@webx.raydaftYaTP>,
"luis a" <l_alvergue@NOCAPITALShotmail.com> wrote:

> Hi, I have recently started using MATLAB for a DSP and a
> Communication Theory class. I have some questions about how MATLAB
> does some things.
>
> 1. To plot a graph, say a sinusoid, I always do this:
> t=0:.1:10;
> a=sin(t);
> plot(t,a)
> What does MATLAB do to generate the data for the points that are not
> in increments of .1? for example sin(1.13)? Does it interpolate to
> generate the graph? Is this sinusoid only valid for .1 increments? In
> fact, a function in MATLAB is inherently discrete, but we use it to
> model continuous functions (its 'domain' is actually only 101
> samples)?

If you sample a function at 101 points, then all you have
is 101 points. Its no longer a "function". When you plot
those points, you have just 101 points.

If you want to connect the dots, then try doing

help plot

You will see that if you add a third argument to the plot
call

plot(t,a,'-')

then you get a curve composed of line segments between
the dots.

> 2. I'm having trouble mixing up the indices of the array (1..101 for
> t matrix) and the actual values (t(1)=0 t(1)=0.1, etc.)I am doing a
> lot of shifting of functions (such as f(x) = x -> f(x-2) = x-2)
> and this is messing me up, I usually get the error, "indices must be
> positive or logicals.." Mathematically, it makes sense to compute
> f(x(1)-2) for x(1)=1, but it doesn't make sense in MATLAB to ask for
> f(-1). This brings me to the question of what is a reasonable matrix
> size for x. -100:.1:100 ? Does it depend on the precision you need?
> Is there a 'convention' used to model functions?

Matlab does not support indexing arrays with zero or
negative integers.

> 3. I had a misconception that MATLAB was very close to mathematical
> notation. In fact, you have to interpret a lot when using it, often
> going back to the theory to make sure computations make sense. So am
> I using it the 'right' way. Usually only crunching huge amounts of
> numbers?

Matlab really is quite close to mathematical notation.
Is it exact? No, this is not possible. How close is
close?

Do you need to think about what you are doing? Yes.
Use of any tool with no thought employed is a fools
game, regardless of the tool.

Should you check to see if your computations make
sense? Always. ALWAYS. I'll tell you a story.

Long ago, in a land far, far away, I was once a
student of mathematics. My professor assigned a
problem to compute the steady-state temperature
along the length of a bar, given known conditions
at the ends of the bar. I did the computations,
handing in my results with no thought to check my
results for sensibility. After all, I was his best
student. How could I have made a mistake? Should
I have asked myself if a temperature of -5000
degrees made any physical sense? Perhaps. As it
was, I merely gave my professor a good laugh at
my expense, and had the opportunity to redo my
flawed results.

The moral of the story? Think about what you do.
Check your results. Its worth a few extra seconds.

HTH,
John D'Errico

--

The best material model of a cat is another, or
preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945
``` 0 10/17/2004 1:17:59 PM Similar Artilces:

Matlab basic operations
I have recently found some strange behaviour of MatLab and I would appreciate if somebody explained me why it happens and how to overcome this problem. Please run the code: x1 = [1/3 repmat(2/3,1,10)]'; x2 = [repmat(2/3,1,10) 1/3]'; mean(x1)==mean(x2) % because sum(x1)==sum(x2) I get results false. Why are the sums not the same although the difference between x1 and x2 is only the order of elements? Don't feel bad, you are only the 1 millionth person to discover the wonders of floating point arithmetic. Have a read: http://matlabwiki.mathworks.com/MATLAB_F...

basic questions in matlab
Hello, I am new in matlab and i would like help to understand the next lines: ////////////// for n=1:npanels cmn=ffil(rc(:,n),r(:,nw),r(:,sw))+ffil(rc(:,n),r(:,sw),r(:,se))+ffil(rc(:,n),r(:,se),r(:,ne))+f coef(n,:)=nc(1,n)*cmn(1,:)+nc(2,n)*cmn(2,:)+nc(3,n)*cmn(3,:); end //// At this i understand that build a matrix coef(npanels,npanels) rm=(-nc(1,:)*vinf(1)-nc(2,:)*vinf(2)-nc(3,:)*vinf(3))'; //// Build a vector rm(npanels) coef(end+1,:)=1;rm(end+1)=0; %prevents singular matrix - sum of panel strengths on closed body is zero //// Add a new row to prevent singularity, so my question i...

MatLab Basics Question
Hello. I'm extremely new to MatLab. I'm a student... and I have an assignement that requires me to use it. No, I'm not asking for "Can someone do my homework?" I need help with the basics. My professor gave my class a 5 minute tutorial, and then gave us this crazy assignment.. and I'm lost. How do I set up the following in MatLab? I have no clue... The S-MF with two parameters l and r (l<r) is an S-shaped open-right Membership FUnction defined by: | 0, for x<= 1, S(x;l,r))= ---+ 2((x...

Basic matlab question
It is an easy question I guess but I need help I have three columns: day, hour and data exemple: 1 4 22 1 8 120 1 12 510 1 17 245 2 3 37 2 10 311 3 14 362 3 18 131 3 21 26 I have another table with max and min hour for each day and I would like to keep just the data between that max and min and transform the rest in NaN. Each day have different number of data. Can anyone help me? On Aug 20, 12:51=A0pm, Fabian <fabianbat...@hotmail.com> wrote: > It is an easy question I guess but I need help > I have three columns: day, hour and data > exemple: &...

Basic Matlab question?
1. Why isn't 3 divided by 2 equal 1.5 in matlab? 2. In matlab, why is 2/3 equal to 0? Isn't 2/3 equal to 0.667? That's what my Matlab says :) >> 2/3 ans = 0.6667 >> 3/2 ans = 1.5000 So what exactly is your problem? the answers are not abnormal in matlab. try it again properly. "Thomas Cruz" <tcruz1@unm.edu> wrote in message <i83pbo\$dhl\$1@fred.mathworks.com>... > 1. Why isn't 3 divided by 2 equal 1.5 in matlab? > > 2. In matlab, why is 2/3 equal to 0? Isn't 2/3 equal to 0.667? "martin M&...

matlab basic questions
Hi, Pretty new to matlab and also to signal processing. I have few basic questions. Would appreciate if someone answers them ... 1) Is matlab used only for analysis? Can I design a filter and then export the complete design in c 2) I saw that one of the tutorial on filter and it seems to export mainly co-efficients, parameters of a filter. But what about the algorithm in C that is used to process the input? Do we have to write them on our own. 3) Some of the advanced functions like image processing have in build functions. If I wanted to create a standalone function outside of matlab,...

basic operations in matlab
Dear Sir/Madam, Does anyone know if or how I can do the following in matlab ? Suppose that I have a number in exponential notation, as follows a = -5.16016e+073 Is there a way, in matlab, to extract the 73. Is there some function that when I input a I can output the exponent of the number, like in this case it would output 73. Thanks!! "Januj Juneja" <junejaja@email.arizona.edu> wrote in message <g0i21q\$m7t \$1@fred.mathworks.com>... > > Dear Sir/Madam, > > Does anyone know if or how I can do the following in > matlab ?...

How does matlab work in this issue ? a matlab principle question
Hello everyone I have an ODE solver computing the temperature every month during a year this script will do the job for j=1:12 [t,T]= ode45(@monthly_solver,tspan,Tic,[],monthly_heat(j),h2(j),); end where Tic is the intial temperature and J loops represents the months Now the question is about matlab principle and how does it work with the initial condition? i mean as the last temperature of the 1st month is the begining temperture of the 2nd month and the last temp. of the 2nd month is the begining temp. of the 3rd month and so on. Do i need to write a command to do ...

Matlab Architecture Question
I am interested in hearing ideas about the best ways to create "modules" in matlab? The goal is to have one interface, where I can easily switch routines, and have different versions of the routine run. For example, suppose I have a routine to recognize license plates. It needs to be initialized, and then on subsequent calls it needs to be run. Later one, I want to swap the license plate recognition file, with another one, and have the new one take effect. Is there an established 'best practice' for this in Matlab? - Pat [ I'm upgrading to Matlab 2009a, from 2005&...

Basic question on DLLs in Matlab
Does anybody know a good tutorial about how to implement DLLs written in C++ in Matlab? I'm also a beginner in C++, so I practically don't know anything about how to write a DLL (apart from some very basic introduction). I'd be especially interested in how to include functions in the DLL, and how to call them in Matlab. Can be as simple as a standard IO-command. Any help is welcome, so as to get an idea how this works fundamentally. ...

I have a matlab 7.0.1 on windows xp machine, and I was trying to learn guide from the example in the manual, basically there are three push buttons in a panle to choose the type of graph (surf, contour, mesh) and a pop up menu to choose different data, and a axis. I've encountered strange problems. The first time when I finish the gui design and test it, the figure (axis) does not show up, also push buttons are covered by the panel and can not be seen. I have set figure visible. Then I decided to start over, this time I were able to see all the components initially, but after I choose c...

Plots in MATLAB
Dear all, I am attempting to plot the yaw velocity gain for an automobile system in MATLAB. This is straightforward - just an equation to calculate it and then plotting G_yvg on the y-axis against v_x on the x axis. I would like my values for v_x to be from 5 to 50. I attempted to run the code below: -- Code start -- % Bicycle Model for car A - The understeer car m = 1669; I_z = 3144; l_F = 1.178; l_R = 1.567; l = l_F + l_R; C_F = 59410; C_R = 50730; K_us = 9.409*10^-3; g = 9.81; v_x = 5:1:50; % This needs to be values between 5 and 50 G_yvg = v_x/l+(K_us*v_x^2/g); ...

Hi! I am a newbie in case of artificial neural networks. Please answer simple ;-) I need to implement digit classification (OCR) with numbers 0..9 as output and approx. 3800 training images. I also have ~1800 test images. I found the OCR example shipped with Matlab and played with it. It uses a feedforward NN with backpropagation (newff). Here my questions: How can I determinate the optimal number of training images? If I use 3800 it takes some time to train. I played with subsets of 200, 400, 500, 800 images and the results where not linear increasing. Should I "re-train"...

basic MATLAB question #2
I have a script where I input specific columns from a ascii file and perform a function on them. Is it possible to set the name, of the file I import, as some kind of variable so that I don't have to write the filename over and over for each time I import it? This is how I do it now: x = dlmread('asciifile', '\t', 'A1..A100'); y = dlmread('asciifile', '\t', 'B1..B100'); I want to be able to do something like this: filename = 'asciifile' x = dlmread('filename', '\t', 'A1..A100'); y = dlmread('filename&#... Web resources about - Some basic questions about MATLAB operation - comp.soft-sys.matlab

Having trouble getting enough MBE questions right?
If you are practicing and getting less than 2 out of 3 MBE questions correct, you need help to make sure you are ready to pass the bar exam. ...

Volkswagen delays earnings report citing “open questions” on emissions scandal
On Friday, Volkswagen Group said it would be delaying its annual earnings meeting , originally scheduled for March 10, due to "remaining open ...

Econ 210a Memo Question: Slavery and Serfdom
**Week 4 Memo Assignment: Slavery and Serfdom:** In his *Wealth of Nations*, Adam Smith confidently asserted that slavery was uneconomic–that ...

Zika case sparks questions about sexual transmission
The disease is mostly spread by mosquitoes, but some patients may catch it through sex Joel & Ethan Coen whitesplained diversity: ‘The question you’re asking is idiotic’
I unapologetically love the Coen Brothers’ films, but after reading this Daily Beast interview with them… I might not love them as people. The ...

Goodell answers Curran’s question on NFL’s PSI reports