Answered
Multiplying two vectors to form a matrix
z = sqrt(x .^ 2 + y.' .^ 2) But, of course, this does not match "multiply them". If you want a multiplication: x .* y.' [ED...

4 years ago | 0

| accepted

Answered
how to remove columns from a 3D array, considering user input
Either use square brackets for the input: b = input('Indices enclosed in square brackets: '); % Type in: [1,5,7] Or input a s...

4 years ago | 0

| accepted

Answered
how to do a for cycle for cell arrays
And the next question concering indices hidden in the names of variables. Use an array instead. In your case, data2 is sufficie...

4 years ago | 0

| accepted

Answered
how to use a for cycle with strings as variables
As soon as you do not hide indices in the names of variables, but use arrays instead, the code is trivial: for k = 1:10 writ...

4 years ago | 0

| accepted

Answered
Using an external array in ode45
This cannot work for several reasons: ODE45 is designe to integrate smooth functions with a certain accuracy. Using non-smooth ...

4 years ago | 1

| accepted

Answered
How to get the correct answer for LU Decomposition with partial pivoting?
You forgot to apply the permutation matrix P to b. The results are correct: P * L * U - A % == zeros, fine b = P * b; Then ...

4 years ago | 0

| accepted

Answered
searching first two consecutive ones and set to 0
y = [0 0 1 1 1 1 1 1 1 1 1]; index = strfind(y, [1, 1]); if any(index) y(index(1):index(1)+1) = 0; end y

4 years ago | 0

Answered
Apply logical mask to every matrix in array
B = reshape(1:24, 2,3,4); mask = logical([1,0,1; 0,1,0]); sB = size(B); B = reshape(B, [], sB(3)); % Join the first tw...

4 years ago | 0

Answered
define a pattern to use with dir and get the file names containing numbers
This does not work with the patterns of the operating system. Use a regexp call to filter the names instead: List = dir('*.t...

4 years ago | 1

| accepted

Answered
Suppressing outputs (ans) in MATLAB
You need a semicolon after the call of the function: paths = CEVPaths(S,r,q,vol0,beta,T,N,NPaths); % ...

4 years ago | 1

Answered
i want to double titles in one graph
This works using the text() command.

4 years ago | 0

Answered
Error using second . Invalid date/time class. (I am working on guide)
A bold guess: persistent timein if x >= p_x(1) && x <= p_x(2) && y >= p_y(1) && y <= p_y(2) timein = datetime('now'); ...

4 years ago | 1

Answered
want a rows to split into multiple rows
X = ones(1, 90); Y = reshape(X, 3, []); % 2nd argument is determined automatically % The long form: Y = reshape(X, 3, nume...

4 years ago | 0

| accepted

Answered
invalid index in program
Use the debugger to examine the cause of problems. Type this in the command window: dbstop if error Run the code again until i...

4 years ago | 0

Answered
MATLAB R2021b error running installer
What does the event viewer tell you about the occurring problems? Do you try to run the installer from the protected download f...

4 years ago | 0

Answered
How do I find the mean of certain parts of a cell array?
This is easy, if you store the values in a numerical array instead of a cell. Why do you prefer a cell array? But you can creat...

4 years ago | 0

| accepted

Answered
If value in one vector is in another, assign the value of the other column of the second vector to a third
I do not understand exactly, what you are asking for. A guess: T = 0:20; s = zeros(1, numel(T)); stimuli = [4 8 14 2 16 6 15 ...

4 years ago | 0

Answered
the length of the time span in ode45
The small discretization and rounding errors accumulate over the time. Small deviations of the initial values can be amplified a...

4 years ago | 1

| accepted

Answered
sort 4th dimension of a 4D matrix with indexing
Maybe you mean: for i=1:83 % vols(:,:,:,i)=vols_sorted(:,:,:, bSortIdx(i)); vols_sorted(:,:,:,i) = vols(:,:,:, bSortI...

4 years ago | 1

| accepted

Answered
Trying to get the user to input consecutive values
for i = 1:length(Rtot) If Rtot is a scalar, the loop runs one time only. I guess you want: for i = 1:Rtot The message "What i...

4 years ago | 1

Answered
I CODED THE PROGRAM BUT DON'T KNOW WHY STATEMENT IS NOT SHOWING, Using the singular value decomposition, prove that σ¯(AB) ≤ σ¯(A)¯σ(B)
The problem is: for i=10: size(A, 1) size(A, 1) replies 5. Then the loop from 10 up to 5 is not entered at all. Do you mean: ...

4 years ago | 1

| accepted

Answered
Write a function that gives a tree with one input
n = 9; disp(char(10 * (abs(-n+1:n-1) < (1:n).') + ' ')) Or with a function: affAbre(n) function affAbre(n) s = repmat(' '...

4 years ago | 0

Answered
Vectorising Multiplying each column from a matrix with a square matrix and the tranpose of this column
Then please post you code. It is much faster on my computer: h = rand(2790, 3591); Pn = rand(2790, 2790); tic R = zeros(1,...

4 years ago | 0

Answered
How to convert table to a csv file and save it in a remote location?
Folder = 'D:\Your\Folder'; File = [all_files(k).name(1:end-8) '_.csv']; writematrix(Stats, fullfile(Folder, File));

4 years ago | 0

| accepted

Submitted


WindowAPI
Set figure size, top-most, transparency and pixel mask, multi-monitor etc by Windows API

4 years ago | 5 downloads |

5.0 / 5
Thumbnail

Answered
Generate a sine wave that has no stop-time
f = 5; a = 1; Fs = 1000; t1 = 1; figure; while 1 % Runs until you press Ctrl-c t = 0 : 1/Fs :t1-1/Fs; x =...

4 years ago | 0

| accepted

Answered
Using number/counter instead of changing all variables names that end on same index
Do not hoide indices in the names of variables. This is a standard pitfall for beginners and discussed frequently. Use real indi...

4 years ago | 0

| accepted

Answered
How to simplify code into a for loop?
M_diag = rand(4,4); C_diag = rand(4,4); K_diag = rand(4,4); a = phi(1:4, 1); q_f = a ./ (diag(M_diag) .* s .^ 2 + diag(C...

4 years ago | 0

| accepted

Answered
TUTORIAL: Comma-Separated Lists and How to Use Them
An interesting application of comma-separated lists are dynamic indexing. You can use it to extract a specific dimension of a mu...

4 years ago | 2

Answered
how to write summation
S = 0; for p = 1:i+1 % Indices are 1-based in Matlab S = S + A(p) + C(i - p); end

4 years ago | 1

Load more