Answered
Subtraction is not working in while loop
If you do not change the value of the variable used in the condition of the while loop, this loop must run infinitly: x = rand;...

5 years ago | 0

Answered
Why do I receive an error with the save function?
save gets the name of the variable, nit the variable itself: save(matFile, 'mypadCBCTimage', '-append', '-nocompression'); % ...

5 years ago | 0

| accepted

Answered
Problem using if statements in for loop
Welcome to the world of numerical maths. See: FAQ: Why is 0.3-0.2-0.1 not equal to zero? The standard example is: any((0:0.1:1...

5 years ago | 0

Answered
Moving Average with timestep
A simple average over 2 elements (length of M can be even or odd): Len = numel(M); v = (M(1:2:Len - rem(Len, 2)) + M(2:2:Len...

5 years ago | 0

| accepted

Answered
Assign nearest maximum value.
Why 30 and not 20? Both have a distance of 5. A = [10,20,30,40]; S = 25; [~, index] = min(abs(A - S)); A(index)

5 years ago | 0

Answered
Why won't this ODE setup work?
Omit the "(t)" in the output: [ceSol, csSol, cesSol, cpSol]= dsolve(odes,conds);

5 years ago | 0

Answered
Reshaping Structure in every iteration
V = []; for i = 1:10 V = cat(1, V, rand(5 + 10 * (i - 1), 1)); M(i).position = V ; end

5 years ago | 1

Answered
Is it possible to improve the performance of my script?
Some hints: Avoid global variables, because they impede the debugging massively. If a code grows (e.g. over 20'000 lines of cod...

5 years ago | 0

Answered
How to generate random packets of fixed size for modulation?(e.g. I want to set the size of my packets to 1440 bytes using randi(imax, s1, s2)?
I'm not sure what you are asking for. Maybe this helps: % 1440 random bytes: data = randi([0, 255], 1, 1440, 'UINT8');

5 years ago | 0

Answered
437.49999999999999999999999032463 / 0.99999999999999999999999999999999 Rounds out
Again: Matlab stores floating point values in IEEE754 format. This is the standard format used in CPUs also. Variables of type ...

5 years ago | 2

Answered
error vectors must be of same length?!
A bold guess: E = abs(((xold - x) ./ x) * 100); % ^ insert this . for elementwise division ?!?

5 years ago | 0

Answered
problem with matrix dimension
How are input and output related? Maybe one of this methods do, what you need: x = rand(51, 500); y1 = x(:, 1:80); ...

5 years ago | 0

Answered
Unable to import .csv file
The message is clear: "Unable to find or open 'Rho_ISA.csv'" This means, that this file is not found in the current folder. So ...

5 years ago | 0

| accepted

Answered
Create calibration checkerboard using built-in function
nX = 5; % Number of columns nY = 4; % Number of rows C = zeros(nY, nX); C(1:2:nY, 1:2:nX) = 1; C(2:2:nY, 2:2:nX) = 1; im...

5 years ago | 0

Answered
Convert file with negative value and nan to double
importdata is extremely smart.Try this: S = fileread('Au_1_E_chem_experiment_SPR_angle_offset_after_PEG.dat'); S = strrep(S, '...

5 years ago | 1

| accepted

Answered
game of life count matlab neighbor name
mod(a,b) replies 0 when the value is wrapped. 0 is no valid index in Matlab. So use instead: mod(a - 1, b) + 1 By the way, the...

5 years ago | 0

Answered
How to fix " ''Value' must be a double scalar within the range of 'Limits'
Use the debugger to examine the problem: dbstop if error Run the code again until Matlab stops at the error. Now check the val...

5 years ago | 0

Answered
What is this Number? 31.006276680299820175476315067101
Matlab uses IEEE754 doubles to store numbers. They have about 15 valid digits. You provide many more digitis in your input, but ...

5 years ago | 1

| accepted

Answered
Hello everyone, could you kindly translate and explain the command I am writing below into words?
XM(2:end) > 126.5 & XM(1:end-1) < 126.5 % A This replies a logical vector, which is TRUE, if the value on the left side is ...

5 years ago | 0

| accepted

Answered
Delete the same numbers appeared in different rows
Are the rows unique? If so, just join all rows to one vector: X = [5 14 9 6 7 8; ... 1 10 6 2 3 4; ... 14 23 18 15 ...

5 years ago | 0

| accepted

Answered
solving Tuned Mass Damper using ODE45, need help putting in equation as parameter to solve
As far as I can see, you have everything you need already. [t,x] = ode45(@(t,x) A * x + [0; 0; sin(om*t); 0], tvec, x0); If ...

5 years ago | 1

| accepted

Answered
How to plot multiple lines from a for loop iteration?
You do create a lot of plots, but all have the same value so they conceal eachother. A small change to demonstrate this: R = 2...

5 years ago | 0

Answered
Center-justifying sprintf() values in a uitable
See: https://www.mathworks.com/help/matlab/ref/uistyle.html#mw_835eaae9-b0c6-4aa9-b8c6-2ff5cf761137 https://www.mathworks.com...

5 years ago | 0

| accepted

Answered
rename files using MATLAB
This cannot work: filePattern = fullfile(myFolder, '/time%3.3d/slice%3.3dtime%3.3d.png'); theFiles = dir(filePattern); The f...

5 years ago | 0

Answered
Why does my graph come out wrong?
fplot(@(x) ((x.^2)-1).^(2/3))

5 years ago | 0

Answered
BUTTER function returning slightly different results for Signal Processing Toolbox in R2020b and R2021a on same computer (Win10)
You can compare both results with this cheap implementation of a high pass Butterworth filter: format long g [num, den] = bu...

5 years ago | 0

Answered
My implemetation for Newton's method doesn't seem to be working
I've cleanup the code, e.g. removed the not needed "x_old". Avoid using the names of important Matlab functions as variables: ep...

5 years ago | 0

| accepted

Answered
Get plot lines title in a GUI plot by mouse click on each line
You can define a ButtonDownFcn for the lines: LineH(1) = plot(1:10, rand(1, 10), 'r', 'DisplayName', 'Line 1'); LineH(2) = plo...

5 years ago | 0

| accepted

Answered
Error on using ODE45 and cannot prompt output
I get a different error message, which is very clear: k=1e9; r = 4.31e-3; kt=0.9; D=1; timespan=[0 30]'; C0=40000; first=...

5 years ago | 0

Answered
Looping over an array using Fibonacci numbers as a range to calculate the mean
What should happen with the last chunk, if you cannot find enough elements in the input data? Should the 1st term really be: me...

5 years ago | 0

| accepted

Load more