need help for matlab [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This figure illustrates my problem:
t (in the X1 calculation) value changes from 0 to etz. If its value reaches etz it has to start from 0 again and again.
This situation has to continue during simulation (I need a loop!). However, t is simulation time and I cannot force it to be zero. So maybe I need a parallel time to the simulation time but I don't how to create it.

Use modulo operator.
http://www.mathworks.com/help/matlab/ref/mod.html
For example:
X1 = abs((mod(t,e*tz)-e*tz/2)/(1.125*c*tz))
This part:
mod(t,e*tz)
Will be >= 0 and < e*tz and will repeat the way you want.
In the future, please provide a better title for your question. Also, providing a screen shot of your code is not the preferred way to include code.

Related

Is it possible to plot bars with filled pattern in Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to plot bars with filled pattern in Matlab, like this figure?
I attempted to use applyhatch_pluscolor link however, I couldn't make it work (attempt below). Is there an easy / feasible alternative?
Test code:
bar(rand(3,4));
[im_hatch,colorlist] = applyhatch_pluscolor(gcf,'\-x.',1,[],[],150);
Then I changed the source code, from bits = hardcopy(h,'-dzbuffer',['-r' num2str(dpi)]); to bits = print(h,'-RGBImage',['-r' num2str(dpi)]);.
I got the figure below. However, this is still far away form the desired result.

How to create a a:d:b vector to create and display "sin(0), sin(pi/n), sin((2*pi)/n), . . . , sin(2*pi)]" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been trying for a while to get this to work but I don't seem to be getting any closer to a solution.
I'm not sure of what the pattern is and what to write for the "d" value in a:d:b
Clearly you want to start from 0 (a) and go to 2*pi (b).
Now the question comes what is your step size (d)?
From your example you can see that you are changing from 0 to pi/n.
And from pi/n to 2*pi/n.
This means your step size is d=pi/n
Once you defined your n, e.g:
n=10;
you can do the rest like this:
x=0:(pi/n):(2*pi)
y=sin(x);

Why I get this Error? (State Space) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Could someone explain me what I must change in my model?
Model
The error messages are pretty clear and self-explanatory. The reason you get the error is because B is of dimension 4x2 and you are trying to do B * Xr where Xr is of dimension 1. According to your equation, you need to do B*U where U = [dXr/dt; Xr];. However, using the derivative block is never a good idea in Simulink if you can avoid it, especially with a step input. Think about how you want to formulate the inputs to your state-space.

Error with square root function and powers in Matlab R2014b [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am carrying out a series of calculations using the sqrt() function. My colleagues and I have noticed that we get different results when using the same inputs. Has anyone encountered this problem before?
This is an example:
input1 = 4;
input2 = 8;
result = sqrt(input1^2 + input2^2)
Result then displays a different value from my colleagues result. We have contacted MathWorks about this issue and have yet to receive a reply.
My team and I came across the same problem a year or two ago.
MathWorks explained that the sqrt() function has an issue with powers when they are added. To overcome this issue and achieve the same result, square each term outside of the sqrt() function:
input1 = 4^2;
input2 = 8^2;
result = sqrt(input1 + input2)
This solved it for my team and I. MathWorks didn't clarify as to the reason for the issue, but told us they were in the process of updating their documentation (haven't seen anything as of yet).

How to convert a negative to non-negative in matlab [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
This is rather a general question.
Actually I have a value x=-77 (dBm) and I want to change it to dB so the command would be y=pow2db(x). The problem is it does not accept negative values. So how do I change this to non-negative and then calcuate y?
Your comments are highly appreciated.
Thanks in advance
You can use the abs() function Matlab provides.
example:
abs([-2 2])
ans=
2 2
Still check what you are doing. Logarithms work in a special way, and you may not be wanting the logarithm of the absolute... just check :D
I would guess one of these two possibilities:
y = pow2db(abs(x))
or
y = pow2db(abs(x)) *sign(x)
Not sure whether either one of them would be meaningfull though.