Answered
Index for subfolders without *.pdf files
Simpler and more robust: D = 'path to the main folder'; S = dir(fullfile(D,'*')); N = setdiff({S([S.isdir]).name},{'.','..'}...

7 years ago | 2

| accepted

Answered
removing NaN values from mat file
load into an output variable (which is a scalar structure), then loop over the fields: https://www.mathworks.com/help/matlab/re...

7 years ago | 2

| accepted

Answered
fprintf matrix question. Need help.
No loop is required: >> x = 1:8; >> y = exp(x); >> fprintf('The force in link (%d)= %g N\n',[x;y]) The force in link (1)= 2....

7 years ago | 0

| accepted

Answered
Weird reading data: seed
The problem is data.seed. When you concatenate that numeric value onto character vectors MATLAB does not implcitly convert the ...

7 years ago | 0

Answered
Changing the For LOOP conditions
If val has a value either 1 or 2: for k = 1:val:n If val is a boolean (i.e. 0 or 1) then simply do either of these: for k = 1...

7 years ago | 0

Answered
What should I use instead of cd?
Your fullfile usage (which you commented out) does not make much sense, in particular: concatenating everything together before...

7 years ago | 0

Answered
Extract files of specific extension from already searched folder
>> S = dir('*.*'); >> S.name ans = . ans = .. ans = archive ans = iregexp.m ans = iregexp.png ans = iregexp.zip ans = ir...

7 years ago | 1

| accepted

Answered
Derivative of cell with matrices
fun = @(m)diff(m,1,2); out = cellfun(fun,X,'uni',0);

7 years ago | 0

| accepted

Answered
Is there a way to select a good color scheme for easy figure viewing
Do NOT use jet ! Read these to know why: https://blogs.mathworks.com/steve/2014/10/20/a-new-colormap-for-matlab-part-2-troubles...

7 years ago | 1

| accepted

Answered
Create a matrix from two matrices
>> GG = [S,[G(1,:);S(2,end)+cumsum(diff([0,G(2,:)]))]] GG = 1 2 1 2 1 3 4 1 2 2 3 4 5 ...

7 years ago | 0

| accepted

Answered
Optimization with loops Error in optim.problemdef.OptimizationProblem/solve
I don't see a simple vectorized solution, but one for loop will be quite efficient: A = [1;3;5;7] B = [10;12;14;19] C = nan(s...

7 years ago | 1

Answered
Need help fixing Vercat error
This line will cause an error: % ' '... If you want to continue to the next line then you need to use an...

7 years ago | 0

| accepted

Answered
Problem using the matlab function randsample
MATLAB is trying to access the wrong randi function. This might occur if you created your own randi function, or a third-party ...

7 years ago | 0

| accepted

Answered
variable format issue using copyfile
Your main bug is on this line: copyfile('finalImg1', 'destDir1'); Your code looks for files literally called 'finalImg1', whic...

7 years ago | 1

| accepted

Answered
How to save every answers in matrix with 2 for loops.
You don't need loops, with the correct indices and one simple addition: >> [X,Y] = ndgrid(1:4); >> d1(X(:),:) + d2(Y(:),:) an...

7 years ago | 0

| accepted

Answered
Error using interp1>reshapeAndSortXandV (line 424) X and V must be of the same length.
Assuming that meas.acc.data and meas.acc.time are vectors with the same number of elements, then diff on the data vector will re...

7 years ago | 1

| accepted

Answered
Combine strings and doubles and export to .txt
You can do this quite easily without any loops: C1 = {'Node coordinates and Elements','Coordinates'}; C2 = {'End Coordinates',...

7 years ago | 0

| accepted

Answered
How to load in .m files in a sequence to Matlab?
"The problem is that I cannot load in all .m files at once..." Your question is confusing: .m files contain code (and in genera...

7 years ago | 1

| accepted

Answered
Represent results in vector format.
>> A = 1:10 A = 1 2 3 4 5 6 7 8 9 10 >> B = [1,25,31,41,11,61,7,81,31,11;81,3,71,31,31,6,11,8,6...

7 years ago | 1

| accepted

Answered
Is there a way to avoid repeating time-consuming calculations from odefun in the events function?
"Is there a way to do the time-consuming calculations only once at each time step?" Not really, because numeric ODE solvers do ...

7 years ago | 0

| accepted

Answered
Numerical cell value changes to random symbols when using strcat - help needed
They are not random characters at all, they are in fact exactly the characters with exactly those character codes that you speci...

7 years ago | 0

| accepted

Answered
Fibonacci sequence for loop
Your while loop does not exit when you probably think it should... Actually you will get the correct answer for m=3, 5, 8, 13, ...

7 years ago | 1

| accepted

Answered
Dir on UNIX does not return .folder subfield
This has nothing to do with Unix vs. Windows OS. The feature of recursive folder searching and returning the folder was introduc...

7 years ago | 0

| accepted

Answered
Reshape a 3D matrix
Rather than using meshgrid it would be simpler to use ndgrid: >> x = [1 2 3]; >> y = [4 5 6]; >> z = [7 8 9]; >> A = randi(9...

7 years ago | 0

Answered
How to recognize it is uppercase ,lowercase , or other sign ?
Your logic is incorrect, you should be using &&, not || Also you are comparing against strings of the character values, whereas...

7 years ago | 1

| accepted

Answered
Rearrange an array based on another array
General solution: >> [~,idx] = ismember(SP,SPI); >> V = VI(idx) V = 10 10 20 10 15 20 5 10 15 15 5 ...

7 years ago | 0

| accepted

Answered
Create a new array from an intersection of two previous arrays
>> A = [1 1 1 1 4 4 4 4 6 6 6 6 6 6]; >> B = [2 2 2 2 2 2 2 2 2 2 7 7 7 7 7 7 7 7 8 8 8 8 9 9 9 9]; >> N = min(numel(A),numel(...

7 years ago | 0

| accepted

Answered
Move on to next iteration when condition is satisfied, specifically when using functions
Adding return does not skip to the start of the next loop iteration, it just exits the function. But you can easily return NaNs...

7 years ago | 0

| accepted

Answered
How to evaluate function with two variables
>> t = 0:0.1:0.5 t = 0.00000 0.10000 0.20000 0.30000 0.40000 0.50000 >> x = (0.2:0.2:0.8).' x = 0.2...

7 years ago | 0

| accepted

Answered
Obtain lines of a matrix according to its position.
All you need is some very basic indexing: B = A([2,4],:) Very basic MATLAB concepts, like how to use indexing, are explained i...

7 years ago | 1

| accepted

Load more