MATLAB plot of 2 variables defined by an equation [closed] - matlab

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
I have the following query. I want to plot in MATLAB the following equation :
i + s - ln(s)/sigma = constant (i and s are variables)
for a given value of constant and sigma. The equation is between s and i. the value of sigma is 0.5 and value of constant can be assumed to be 1.
I want to plot the above equation. i and s both are function of time but in graph we need graph of s & i only. i on y axis and s on x axis.

try fimplicit
https://www.mathworks.com/help/matlab/ref/fimplicit.html
f=#(s,i) i + s - log(s)/2 - 5;
fimplicit(f,[1 5 2 10])

Related

Generation of coordinates from a range of values in matlab [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 2 years ago.
Improve this question
distance = [10:.1:30];
norm_dist = normpdf(distance,20,2);
I am trying to generate x,y,z coordinates from the above range of normally distributed values but don't know how to do. Please help.
The normal_dist variable generates values in a normally distributed fashion. I want to use these values to randomly generate the x,y,z, coordinates values. The separate x,y,z values need to be generated not a 3-D array
If I understand your question correctly, you need to use meshgrid function as well
distance = [10:.1:30];
[X,Y,Z] = meshgrid(distance);
F = normpdf(X,20,2);
As a result you'll get 3d grid with those numbers
meshgrid() creates a matrix you can use for further calculations. Probably you will need to make normpdf dependent on X, Y, Z at the same time, e.g.
F = normpdf(X.^2+Y.^2+Z.^2,20,2)

Inverse of 1D vector Matlab [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 4 years ago.
Improve this question
I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].
Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].
I can now make a graph with plot(x,y):
Now, however, I want an inverse graph, so I make a plot with plot(y,x):
I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.
How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?
Upd.: If I try just 1./x:
I have managed to find a solution, so for anybody who also need its:
x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);

Random matlab matrix with at least .4 and at most .6 ones per column [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 6 years ago.
Improve this question
I'm creating a matrix in matlab of size n that contains only ones and zeros. The easiest way to do that is round(rand(m,n)) for a matrix of size mxn, but it creates in some cases rows that have all zeros or all ones. I want to put a lower and upper bound in the number of ones that each row has. Is there an easy way to do that?
Thanks
This is just for one column, but can easily be extended to a matrix:
v = zeros(m,1); % column
Fill the beginning of the column with at least 40% and at most 60% ones:
v(1: floor((0.4+(0.6-0.4)*rand())*(m+1))) = 1;
Shuffle the column:
v = v(randperm(numel(v)));

Distribution of error by histagrams [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 8 years ago.
Improve this question
I have two data set in my hand, they are 720*1 size column matrices , how can ı calculate the error and draw the error ditribution diagram? One of them are actual data and the other is the predicted one.
In matlab,
true = rand(720, 1); % or wherever else you get your data
pred = rand(720, 1); % or wherever else you get your data
errs = pred - true; % the error in each predicted value
nbins = 50; % number of bins for histogram
hist(errs, nbins); % plot the histogram

Plot excel data 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 8 years ago.
Improve this question
How would I do to plot an excel file which consist of a set of data in two columns. Would like to make my first column data representing the y-axis and second column data in x-axis.
Its really easy if you use the function xlsread(). Your code should look like
A = xlsread('Data.xlsx');
x = A(:,2);
y = A(:,1);
plot(x, y);