Answered
Comparing the performance of colon, loop, and cell indexing
"Am I missing something?" 1- accessing data in non-contiguous locations is slow. Consider your indexing output(k,:): because MA...

6 years ago | 0

| accepted

Answered
How can I use a variable number of structure fields as function arguments?
Use struct2cell and a comma-separated list: >> X = fieldnames(MyStruct); >> Y = struct2cell(MyStruct); >> C = [X(2:end),Y(2:e...

6 years ago | 2

| accepted

Answered
finding same pattern files from two different folders and copying to other folders
Read the folder contents using dir. Extract the timestamps (e.g. regexp or indexing) Call intersect on the timestamps, returni...

6 years ago | 0

| accepted

Answered
How to pull value of table for char array?
"When I use the code" t(1,'Domain') then your indexing returns a table, because parentheses is used to return a table (i.e. u...

6 years ago | 2

| accepted

Answered
Executing same function in different elements of an array
Try something like this: B = [2500,5000,...]; % begin indices E = [2800,5300,...]; % end indices N = numel(B); C = cell(1,N)...

6 years ago | 0

| accepted

Answered
Matrix product: inv or \ ?
"Why using \ is faster than inv? Is there a numerical reasone?" Yes: because the two division operators use completely differen...

6 years ago | 0

| accepted

Answered
The min and max function return incorrect result!
The default display format short displays arrays with five significant figure precision and a common multiplier for all values i...

6 years ago | 1

| accepted

Answered
For loop problem; could you help?
thi = 0.1:0.1:1; T = 273.15:1:273.15+60; %%% temperature N = numel(T); w = nan(numel(thi),N); % preallocate! Pg = nan(1,N); ...

6 years ago | 0

| accepted

Answered
Create Matrix By Several Matrices These Matrices Have Elements By Equations
Having lots of numbered variables is not a good approach, you should place all of those sub-matrices into one cell array when th...

6 years ago | 0

Answered
Too many input arguments. (the equations and conditions are given i am running the code but giving error kindly suggest me )
The anonymous function F only has one input argument: F = @(as)... but you are calling it with two inputs: f = F(asc,L); Pro...

6 years ago | 0

Answered
How to perform mathematical operation in columns on certain elements and make the other elements zero??
Something fancy... >> M = [0,0;0,0;1,0;2,7;5,8;3,11;4,12;2,9] M = 0 0 0 0 1 0 2 7 5 8 ...

6 years ago | 0

Answered
removing specific values in a cell array
>> A = {1:10,1:10}; % square brackets are not required. >> F = @(a)a(a>=3&a<=8); >> B = cellfun(F,A,'uni',0); >> B{:} ans = ...

6 years ago | 1

| accepted

Answered
convert a cell array to 3-d array
B = permute(cat(3,A{:}),[3,1,2])

6 years ago | 1

| accepted

Answered
How do I split cells in an array and save data into a bigger cell array?
Use a comma-separated list to help concatenate them into one cell array or string array: >> arr = {'hello i welcome you';'what ...

6 years ago | 0

| accepted

Answered
cover cell array into vector
Numeric arrays do not have empty elements: every element has one value. But you can easily store the sizes and recreate the cel...

6 years ago | 0

| accepted

Answered
Removing loaded variables from workspace after changing name with eval
Do NOT use eval for such trivial tasks as importing data. Either access the fieldname, e.g. S = dir('C:\MyFolderPath'); N = n...

6 years ago | 0

| accepted

Answered
Replacing values in cell array in for loop
It is simpler and more efficient to use max: F = @(m) max(m,spect_threshold); Y = cellfun(F, Y, 'UniformOutput', false);

6 years ago | 0

| accepted

Answered
What is the best way to implement thousands of data in multiple matrices ?
I would not use either of the first two methods, because they are an easy way to get latent, almost undetectable errors in your ...

6 years ago | 0

| accepted

Answered
Replacing Values Between a 0 and a 1 in a Vector
This should be reasonably efficient: A = [0,0,0,2,2,2,1,2,1,2,2,0,0]; D = diff(A); B = find([0,D]==2); E = find([D==-1,true]...

6 years ago | 0

Answered
Toeplitz Matrix Generation from 2 MATRICES
>> A = rand(3,3); >> B = rand(3,5); >> N = 4; >> F = @(n)(A^n)*B; >> C = arrayfun(F,0:N,'uni',0); >> C = [{zeros(size(B))},...

6 years ago | 0

| accepted

Answered
Reading data from ASCII file
Importing the entire file data as character, converting to string, spltting that string into multiple little strings, and then f...

6 years ago | 0

| accepted

Answered
if all elemets of a array equal, which array will be choose by MAX function?
There is no inbuilt function, but you can do it yourself very easily: >> a = [0,0,0,0,0]; >> ida = find(a==max(a)); >> idx = ...

6 years ago | 0

| accepted

Answered
How to set the no if iterations of a for loop dynamically ?
The MATLAB approach is to do these two steps before the loop: create a cell array of the folder names use setdiff or ismember ...

6 years ago | 0

| accepted

Answered
How to save fields of a struct through for loop iteration.
You don't need a loop, just use the -struct flag to save the fields of a scalar structure: save(filename,'-struct','data') Whe...

6 years ago | 0

| accepted

Answered
Declaring types in MATLAB
"When preallocating, is it possible to declare types? " When preallocating you can select any suitable data type, e.g.: A = ze...

6 years ago | 0

| accepted

Answered
Multiple outputs by a loop
Replace the fopen with these two lines: fnm = sprintf('output%d.txt',i); fid = fopen(fnm,'wt');

6 years ago | 0

Answered
how can i plot the function of each function?
"what's wrong on this code?" if does not change subsets of an array like that (you would need to use if inside of a loop). You...

6 years ago | 0

| accepted

Answered
Skill with regexprep?
This should get you started: >> str = '5*0.02 0.02 0.04 0.08 0.15 0.3 0.5 1 2 3 30*5 30*10 30*20 30*40 30*60'; >> fun = @(n,c)...

6 years ago | 0

| accepted

Answered
Creating a structure from a cell array with nested structure fields
Nope, that won't work. Best approach: split on the period characters, then use setfield and getfield as appropriate: S.field1....

6 years ago | 0

| accepted

Answered
(1/3)*3-1 evaluates to 0 instead of some numerical error. Why?
The reason is very simple: because 1 is the closest (double) binary floating point number that can approximate the value of (1/3...

6 years ago | 2

| accepted

Load more