Answered
What is the best practice in MATLAB to increase a variable in a cycling way?
Just use |mod|: for k = 1:10 1+mod(k-1,5) end which displays: ans = 1 ans = 2 ans = 3 ans = ...

9 years ago | 0

| accepted

Answered
Can't change directory to the existed folder on Windows 10, 'Name is nonexistent or not a directory'
See: <https://www.mathworks.com/matlabcentral/answers/354614-cd-to-onedrive-doesn-t-work-on-windows-10-build-16273-1>

9 years ago | 1

| accepted

Answered
How do I display only the last iteration
Move the |fprintf| to _after_ the loop: theSum = 0; for k = 1:numel(x); theSum = theSum + x(k); end fprintf...

9 years ago | 0

| accepted

Answered
How can I extract entries from a matrix and a vector into a new vector in a specific way?
To get the correct order: >> [reshape(M.',[],1);t(:)] ans = 0.60000 0.80000 -0.80000 0.60000 ...

9 years ago | 0

| accepted

Answered
i tried to run this instead i got error message : Error: Expression or statement is incorrect--possibly unbalanced (, {, or [. ..., please help me out , i attached a picture of l curve am trying to plot . thanks
Check this line: loglog(x,y,'k+','LineWidth',1.5,'Linestyle','--',... The three dots means that it continues on the next...

9 years ago | 0

Answered
Multple switch expressions needed to run
As Rik Wisselink hinted: scenario = {'a','b'}; for k = 1:numel(scenario) switch scenario{k} case 'a' ...

9 years ago | 1

| accepted

Answered
minimum of different sized cell arrays using cell2mat error
>> min([Y{:}]) ans = 10

9 years ago | 2

Answered
convert structure class to double class
Fake data: >> A.F1 = [1;2;3]; >> A.F2 = 4; >> A.F3 = [5;6]; >> A.F4 = [7;8;9]; To concatenate all fields of a s...

9 years ago | 1

| accepted

Answered
convert structure class to double class
Using your example cell array: >> A= {[99;11], [44;11;33;88;66], [77]}; >> cat(1,A{:}) ans = 9...

9 years ago | 1

Answered
Finite Element Triangular Mesh Generator
<https://www.mathworks.com/help/matlab/delaunay-triangulation.html>

9 years ago | 0

| accepted

Answered
how to add zeros around a matrix?
>> conv2(A,[0,0,0;0,1,0;0,0,0]) ans = 0 0 0 0 0 0 1 2 3 0 0 2 3 4 0 0 5 ...

9 years ago | 1

| accepted

Answered
How to extract multiple sections of data, separated by sections of text of varying sizes, and create one continuous data file.
Call |textscan| in a |while| loop. You can adapt the method shown in the MATLAB help: <https://www.mathworks.com/help/matlab/...

9 years ago | 0

Answered
Subtraction of rows in matrices
>> diff(dn) ans = 2 3 2 2 2 2 2

9 years ago | 0

Answered
accumarray not working on float subscripts
mat = [ 35046, 0.17 1963, 0.34 1135, 0.51 405, 0.68 99, 0.85 1, 0.85 15, 1.02 2, 1.02]; % set toler...

9 years ago | 0

| accepted

Answered
nanmean gives unexpected results
_"I am calculating nanmean using two different techniques"_ Nope, not at all. Your code does not calculate anything at all li...

9 years ago | 0

| accepted

Answered
Divide a Large Matrix into Smaller Matrices in a Loop
You can define the indexing quite easily: mat = rand(20,5); row = 4; % rows per group grp = size(mat,1)/row; for k...

9 years ago | 1

| accepted

Answered
How to create a semi-diagonal matrix
*Method one: <https://www.mathworks.com/help/matlab/ref/blkdiag.html |blkdiag|>:* >> blkdiag([1,1],[1,1],[1,1]) ans = ...

9 years ago | 0

| accepted

Answered
How can I repeat my setting for multiple figures (in different figure )?
Two simple options: # Set those value as <https://www.mathworks.com/help/matlab/creating_plots/default-property-values.html ...

9 years ago | 4

| accepted

Answered
How to find the largest product?
function [product,ind] = max_product(a,n) product = 0; ind = -1; num = numel(a); for k = 1:1+num-n tmp = prod...

9 years ago | 0

Answered
better method for evaluating matrix
You really need to learn how to write <https://www.mathworks.com/help/matlab/matlab_prog/vectorization.html vectorized code>. So...

9 years ago | 1

| accepted

Answered
how to access individual elements from a variable?
If you want the second element of |a|, then use indexing to get the second element of |a|: >> a(2) ans = 176 Or simp...

9 years ago | 0

| accepted

Answered
How do I evaluate a user-input trigonometric function?
It is simpler to use <https://www.mathworks.com/help/matlab/ref/str2func.html |str2func|>: num = str2double(input('End valu...

9 years ago | 1

Answered
Save multiple run result of script
An alternative to using a loop: download my FEX submission nextname, which will generate the next filename each time you call it...

9 years ago | 1

Answered
Increasing the Specific Matrix Entries by Some Interval
>> A = [21,23,25,27,28,32,31,29,26]; >> idx = cumsum(max(A)==A)>0; >> [A(~idx),max(A)+(0:nnz(idx)-1)] ans = 21 ...

9 years ago | 0

| accepted

Answered
How can i write the code in a m-file that can take any periodic function and calculate its fourier series expantion using matlab?
Download this FEX submission: <https://www.mathworks.com/matlabcentral/fileexchange/31013-simple-real-fourier-series-approxim...

9 years ago | 0

| accepted

Answered
differentiate input dialog strings into either symbols or double precision values
There are several ways your could approach this, depending on what you define as "numeric" (e.g. plus/minus sign, decimal digits...

9 years ago | 0

Answered
How can I extract all values in a row of an array without the its maximum value
>> a = [1,3,6,5;6,7,1,9;5,3,9,10] a = 1 3 6 5 6 7 ...

9 years ago | 0

| accepted

Answered
replace part of matrix to another matrix
For any size matrices, even combinations of different sizes: C = {[1,2;3,4],[5,6;7,8],[9,10;11,12],[13,14;15,16]}; num =...

9 years ago | 0

| accepted

Answered
How to get index of each points in data?
Your code would be much simpler if you called |sort| on the required column: >> [~,idx] = sort(A(:,4)) idx = ...

9 years ago | 1

Load more