Answered
Find empty cells in 3D cell?
The simple MATLAB solution is to use ind2sub. First lets create some fake data: >> A = repmat({NaN},12,125,1216); >> A(5,23,[2...

7 years ago | 3

Answered
Find Structure Field using a string and modify content of data under this field
You can use dynamic fieldnames: https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html fld...

7 years ago | 0

| accepted

Answered
question about indexing of logic matrix
Your mistake is on this line: A=rand(20,3); You correctly wrote that "hel.faces is a m*3 matrix", but you seem to have missed ...

7 years ago | 0

| accepted

Answered
Help using contourc without meshable x-y data
Interestingly contour does not directly call contourc anywhere, instead it passes its input arguments to a contourgroup construc...

7 years ago | 2

| accepted

Answered
decimal to binary conversion of an array
Cell array of character vectors: >> a = [102,2,3,201,8,9]; >> c = arrayfun(@dec2bin,a,'uni',0); >> c{:} ans = 1100110 ans =...

7 years ago | 2

| accepted

Answered
Datetime 'convertfrom' forcing dates to be Jan2019
Your code and question do not seem to be particularly related to your uploaded data, or show some signs of confusion. For exampl...

7 years ago | 2

| accepted

Answered
Read text file - ignoring lines starting with specific character.
nmc = 4; % number of columns in file fmt = repmat('%f',1,nmc); opt = {'HeaderLines',3, 'CollectOutput',true, 'MultipleDelimsAs...

7 years ago | 0

Answered
Evaluate string as structure
The most important thing is to always load into an output variable, then your task is easy: N = 'structure_name'; S = load(N);...

7 years ago | 0

| accepted

Answered
How add multiple variables from one mat files into common mat file in loop ?
The solution is really very simple, you do not need to waste time with loops or dynamic fieldnames. First lets create two examp...

7 years ago | 0

Answered
Find values and positions of a matrix referring to another matrix
This is MATLAB, so you should learn how to efficiently solve tasks like this without loops: >> A = [2,4,7]; >> B = [3,4,6;1,5,...

7 years ago | 1

Answered
How do I take a matlab code file from the internet and use it in matlab
"... and actually import it to matlab?" MATLAB does not require code to be "imported". MATLAB automatically detects all code on...

7 years ago | 0

Answered
How to sum over each n-th element in an array ?
Just use reshape: >> b = sum(reshape(a,1001,[]),2); and checking the output: >> b(1) ans = -6343.8 >> sum(a(1:1001:end)) a...

7 years ago | 0

| accepted

Answered
Plotting values from a set of nested if-else statements in while loop nested in a for loop
An improved version of your script, without the poor practices shown in Jyotsna Talluri's answer: V = 1:1000; N = numel(V); L...

7 years ago | 0

Answered
sorting alphabetically with sortrows: underscore handled differently than in windows
If you actually want to sort filenames into alphanumeric order, then one option is to download my FEX submission natsortfiles: ...

7 years ago | 0

| accepted

Answered
Regular expressions with regexp.
>> str = '20070101'; >> rgx = '(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})'; >> out = regexp(str,rgx,'names') out = yea...

7 years ago | 0

| accepted

Answered
How to call function using list element?
Use str2func, e.g.: function test() C = {'sub1','sub2'}; F = cellfun(@str2func,C,'uni',0); for k = 1:numel(F) F{k}() e...

7 years ago | 2

| accepted

Answered
while loop for series
"what am i doing wrong?" You are not actually adding anything to y on each iteration, instead you completely overwrite y with a...

7 years ago | 0

Answered
Error reading .mat file
MIPAV wrote a dud file. Open that file in any reliable text editor, and you will find that it contains the text "MIPAV is writi...

7 years ago | 0

| accepted

Answered
Matrix as an input argument, multiple outputs
Your indexing assumes that the input matrix has size 2x2. The assignment does not state that restriction, so you should write y...

7 years ago | 0

Answered
problem in writing files
The problem is likely caused by the fact that your images are actually written to a different directory than you think. I stron...

7 years ago | 0

| accepted

Answered
Combining several asymmetric matrices to fit each other
Do this for each pair of matrices A and B: >> A = [-2,6,2,7,1;4,-5,2,3,NaN;6,1,3,NaN,NaN;2,2,NaN,NaN,NaN;4,NaN,NaN,NaN,NaN] A ...

7 years ago | 1

| accepted

Answered
split matrix in diffrent sizes matrixes according to indicies vector
Do NOT create numbered variables. Indexing is simpler and much more efficient. You can use mat2cell to split the matrix up into...

7 years ago | 1

| accepted

Answered
Selecting values from a .txt file which are prefaced by a phrase
You could use textscan to import that file data quite efficiently: opt = {'Delimiter',' =','MultipleDelimsAsOne',true,'CollectO...

7 years ago | 1

Answered
putting the combinations of a sequence in an cell array
>> vec = 1:5; >> fun = @(n)num2cell(combnk(vec,n),2); >> out = arrayfun(fun,1:numel(vec),'uniformoutput',0); >> out = vertcat...

7 years ago | 1

| accepted

Answered
Find the number of a row in a matrix that have a minimum value compare to another specific row
>> A = [0,28;28,0;9,26;29,21;10,32;3,26] A = 0 28 28 0 9 26 29 21 10 32 3 26 >> vec = ...

7 years ago | 1

| accepted

Answered
String to serial date number
datenum(fdate, "yyyy-mm") % ^ this character does not match your date data!

7 years ago | 0

| accepted

Answered
Selecting specific values from anonymous functions
You could call subsref directly, e.g.: subsref(TsMat(thetas),substruct('()',{3,':'})) and similarly for the other function cal...

7 years ago | 2

| accepted

Answered
Create a matrix from some given matrices
>> p = 2; >> N = 3; >> A = randi(9,p,p) A = 6 7 2 1 >> B = randi(9,p,p) B = 3 1 1 8...

7 years ago | 0

Answered
How do I vectorize adding array elements based on indices?
Using accumarray: >> potential = [1,2,3,4,5]; >> train = [8,7,8,7,8,7,8,7]; >> destination = [1,1,1,2,2,2,3,4]; >> poten...

7 years ago | 0

| accepted

Answered
packing function for the file exchange
The problem is a bit obscure, but it is caused by the fact that you have HTML documentation with the same name as your main func...

7 years ago | 1

| accepted

Load more