Community Profile

# Ameer Hamza

### Hong Kong Polytechnic University

2.484 total contributions since 2016

View all

Contributions in
View by

How to plot a, as varibale stored chart?
MATLAB graphics objects cannot be saved as variable by using their handles. Once the figure closes, the handle becomes invalid. ...

alrededor de 4 horas ago | 0

How to replace (in a vector ) every value by the average of the previous n samples? (To smooth a signal)
Try movmean() movmean(SE_rest, [100 0])

alrededor de 4 horas ago | 1

converting cell to struct with fields
Something like this S.DeliArg = [DeliArg{:}]; S.AlgTry = [AlgTry{:}];

alrededor de 4 horas ago | 0

| accepted

Index exceeds the number of array elements?
It seems that you are trying to find a derivative of rho_s w.r.t. T, you can use gradient() function p = 10; a = 1000; b = 0....

alrededor de 4 horas ago | 0

| accepted

How to plot multiple functions with a for loop
H = [0.05 0.1 0.2]; figure; hold on for i=1:numel(H) y0 = 0; t0 = 0; tf = 1; h = H(i); f = @(t,...

1 día ago | 0

| accepted

The ecdf(x) always starts from the origin of the axis

1 día ago | 1

| accepted

How do I show only two colors in my Legend?
You can use the handle returned by plot() with legend() to only show specific legends. For example hold on; p(1) = plot(rand(1...

1 día ago | 0

function or functions of a single variable
You need to pass a function handle fplot(@(x) -exp(-x)+x.^2+2*x+2, [0 1])

2 días ago | 1

Compare every element in a vector and find the minimum distance to a constant value.
Something like this x = [2, 8, 15, 11, 2]; % modified so that it have two minumum distances a = 12; D = abs(x - x.' - a); ...

2 días ago | 0

convert alphabet to coresponding number by using ASCII
Like this char2num = @(c) char(c)-96; Example >> char2num('a') ans = 1 >> char2num('b') ans = 2 >> char2num('...

2 días ago | 0

| accepted

Replace certain elements of vector with the values from another vector
There is no need for a for-loop S_1(m) = S_2(m);

2 días ago | 0

| accepted

App Designer Issues and Suggestions
All the improvements suggested in your question are quite useful. I am just adding this answer so that the question does not aut...

2 días ago | 1

Calculating volume of a tetramesh

2 días ago | 0

find x intercepts numerically
Try this f = @(x) find(diff(sign(x))); Example >> x = [1 2 -1 -2 -1 2 3 1 -2 -3 -2 1]; >> f(x) ans = 2 5 8 ...

2 días ago | 0

| accepted

Make multiple plots of multiple files in for loop
It should be data = importdata(files(i).name);

2 días ago | 0

| accepted

Is it possible to visualize all data in a multiple scatterplot?
Maybe use scatter3() and visualize by using a z-offset. Not sure if it helps in your case h1 = scatter3(table{:,variable},table...

2 días ago | 0

specify axis limit to be nonneagtive
You can set the upper limit to Inf to let MATLAB automatically that axis([0 inf 0 inf 0 inf]) or xlim([0 inf]) ylim([0 inf])...

2 días ago | 0

| accepted

how to know the array of the function that i plot
See this example to convert to strings to function handles and multiply them y1 = 'sin(x)'; y2 = 'cos(x)'; y1f = str2func([...

2 días ago | 0

| accepted

Using fsolve with type double
To use a symbolic equation with fsolve(), first convert it to a floating-point function handle. See matlabFunction(): https://ww...

2 días ago | 0

Creating a new matrix of size A with columns n:n+56 and zeros
Using variable names like A2, A3, A4, ... is never a good idea: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-...

2 días ago | 0

I need to solve a cauchy problem with the Euler Method.
Following shows how to find true solution using symbolic toolbox and plot both of them on same graph % Eulerian Method % Setup...

2 días ago | 0

| accepted

How can I save a vector in a for loop to a pre-allocated cell if my first value of the loop (i) is not 1?
Write the for-loop like this x = 20:5:60; for i = 1:numel(x) % instead of i write x(i) sol{i} = results; end

2 días ago | 0

How to compute monthly average and standard deviation with for loop
If you have Statistics and Machine Learning Toolbox, then you can use grpstat(). For example format long g folder = 'BCC_CSM.x...

2 días ago | 0

Pick a number from an array with a certain probability
If you can use pre-defined functions and you have Statistics and Machine Learning Toolbox, then you can use randsample(): https:...

2 días ago | 0

| accepted

How to create a blue color gradient
An alternate approach using indexed image cols = 2160; rows = 3840; left_color = [1 1 1]; % white right_color = [0 0.25 0.5]...

2 días ago | 1

It depends on how the answer is generated. Suppose the following cases. >> x = {1, 2, 3, 4}; >> x{:} ans = 1 ans = ...

2 días ago | 0

Fractional Order transfer function
See this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/66323-fomcon-toolbox-for-matlab. It provides blocks f...

2 días ago | 0

Speeding up nested for loops that create a matrix within a matrix
Try something like the following code. It might not be faster, however, it made the code concise. Hopefully, you have already in...

2 días ago | 0

| accepted

How to calculate log(a/b) for each two rows at each column ?
a = ... [2 3 6 5 7 4 5 4 7 8 9 6 4 5 8 9 8 5]; b = log(a(2:end, :)./a(1:end-1,:)); Result >> b b = 0.9...

2 días ago | 1

| accepted