Answered
Write data from for loop into a file
You need to open the file _before_ the loop, print the text _inside_ the loop, and close the file _after_ the loop: [fid,ms...

8 years ago | 0

| accepted

Answered
Changing file names based on their filetype extension
D = 'path to the parent directory where the folders are'; S = dir(fullfile(D,'*')); S = S([S.isdir]); for k = 1:numel...

8 years ago | 0

Answered
How to make a scale-able structure array with variable values
_"Is it possible to put a maths expression in there, and if so how?"_ You could define it as a function: >> S.fun = @(le...

8 years ago | 0

Answered
How could I get my function to produce this?
You will need to use a dynamic fieldname: <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variab...

8 years ago | 0

| accepted

Answered
FUN must be a function, a valid character vector expression, or an inline function object. | fzero
You don't need to store the functions in any array, you only need to store the output values: function out = FA(y) out =...

8 years ago | 0

Answered
Getting variables for different files
Just use <https://www.mathworks.com/help/matlab/cell-arrays.html cell arrays>: N = numel(location); A = cell(1,N); B ...

8 years ago | 0

| accepted

Answered
bug in find function
_"bug in find function"_ There is no bug in |find|. You have just discovered that two _different_ floating point numbers are ...

8 years ago | 0

Answered
re-order array structs of arrays
Here is a 1x3 structure with two 1x4 numeric fields: S(1).f1 = 0:3; S(1).f2 = 2:5; S(2).f1 = 1:4; S(2).f2 = 3:6; ...

8 years ago | 0

| accepted

Answered
How to compare elements of two equal size matrices by logical conditionals?
@MARCELA FRAGOZO: simpler and more efficient: C = min(A,B) Try it, and you will see that it does the same as your logic....

8 years ago | 0

Answered
Sorting problem with months in file names, while taking average
Two solutions: 1) Use <https://en.wikipedia.org/wiki/ISO_8601 ISO 8601> dates in the filenames, then they can be sorted using...

8 years ago | 1

| accepted

Answered
Counting up starting from first row of zeros in a matrix, then 1's.
>> a = [1,6,2;7,8,3;4,5,9] % what you want a = 1 6 2 7 8 3 4 5 9 >> m = [0,1,0;1,1,0;0,0,1...

8 years ago | 1

| accepted

Answered
Convert tables to arrays in a for loop
C = {data_1, data_2 ,data_3, data_4,data_5}; D = cellfun(@table2array,C,'uni',0)

8 years ago | 1

| accepted

Answered
Horizontal concatenation of sub-matrix into a bigger matrix based on value of first column
Using <https://www.mathworks.com/help/matlab/ref/unique.html |unique|> and <https://www.mathworks.com/help/matlab/ref/accumarray...

8 years ago | 1

| accepted

Answered
How to copy a structure without a field?
Use <https://www.mathworks.com/help/matlab/ref/rmfield.html |rmfield|>: q = rmfield(p,'field2')

8 years ago | 0

| accepted

Answered
Processing array where the elements are sometimes min/sec and sometimes hour/min/sec
As long as the last unit is always the same then you could use this: >> C = {'28:44','54:08','1:02:34','1:58:33'}; >> V ...

8 years ago | 1

Answered
How can I create a new vector by passing a function each for loop iteration?
_"This is normally a very simple problem in just about every other coding language, except matlab it seems."_ It is really si...

8 years ago | 1

| accepted

Answered
finding unique cell elements from different size of matrix
Your question has nothing to do with |unique|. The element that occurs the most often in a set of data is called the <https://en...

8 years ago | 1

Answered
Import multiple excel files into multiple variables (or matrices)
Your code has a bug in it: you use an absolute file path with |dir| but not with |xlsread|. But the biggest problem is with your...

8 years ago | 2

| accepted

Answered
Is there a way to get the switch and case function to be part of the overall formula?
It is a good start, but you should: * read the help for each function that you use, then you would learn than |input| does no...

8 years ago | 0

| accepted

Answered
How to find a string in the following cell structure?
Storing lots of separate scalar structures in a cell array is less convenient than just using one <https://www.mathworks.com/hel...

8 years ago | 0

Answered
add element to cell
>> idx = ~all(ismember(E,[M{:}]),2); >> M = [M(:);num2cell(E(idx,:),2)]; >> M{:} ans = 1 2 5 ans = ...

8 years ago | 0

| accepted

Answered
How to multiply each row of a matrix with a second full matrix, while applying a formula
In just one line, works for any number of rows of |a| and |b|: >> a = [3,4,5,1;3,2,0,4]; >> b = [1,2,3,4;2,0,2,4;0,4,8,2...

8 years ago | 0

Answered
Information lost when extracting individual images from video.
You should simplify and improve your code, e.g.: * use |dir| to match the |*.mpg| pattern rather than using |endsWith|. * us...

8 years ago | 1

Answered
Can someone help me understand this code. Its a plate bending code.
<https://www.mathworks.com/matlabcentral/fileexchange/32029-plate-bending> The files |coordinates.dat| and |nodes.dat| are in...

8 years ago | 0

Answered
How can I use for-loop to implement variable parameters?
Following the advice of old questions and answers is not a good idea, because the syntax can change. To parametrize a function y...

8 years ago | 0

Answered
Importing data files with the same name in different directories (seeds) , setting them equal to "loop able" variable
_"I will say that I've written a verbose form of this code that sets variables for every import. I have 25 simulations with 20 s...

8 years ago | 1

| accepted

Answered
fprintf linspace and variable IN THE RIGHT ORDER
Get rid of the loop entirely, you don't need it: x = linspace(0,10,p); y = (m*x)+c; fprintf('The y value when x equal...

8 years ago | 0

Answered
Computing the average across columns, while discounting a specific column
Say you have a matrix |M| and you want to get the mean of each row, ignoring the third column: N = 3; % column to ignore ...

8 years ago | 1

Answered
How can I get the length of the intersection of each row of a matrix with another vector?
*Method one: <https://www.mathworks.com/help/matlab/ref/ismember.html |ismember|>:* >> sum(ismember(C,V),2) ans = ...

8 years ago | 0

| accepted

Load more