Answered
combine for loop and ~isinf,but there is an error in every loops except the result in the first loop
v = [3,6,1,Inf]; for k = 1:numel(v) n = v(k); z = n(~isinf(n)) end displays: z = 3 z = 6 z = 1 z = [] "i c...

7 years ago | 0

| accepted

Answered
MatLab function for each two values in struct inside loop
load example.mat C = {example.Name}; D = {example.dates}; M = [example.x;example.y]; [U,~,idu] = unique(D); N = max(idu); ...

7 years ago | 2

| accepted

Answered
Finding substring based on another substring
"What is the most efficient way to get files along the diagonal?" Probably something like this is about as efficient as you can...

7 years ago | 0

| accepted

Answered
I need to save columns from n number of matrices into different variables
Rather than forcing yourself into writing badly designed code (like your very inefficient eval usage inside the for loop), you s...

7 years ago | 2

| accepted

Answered
How can i regexp this sample text?
Here is a regexp-based solution which does NOT use hard-coded variable names (it automatically detects the variable names), and ...

7 years ago | 2

Answered
save matfile with current time stamp
Do NOT concatenate paths and filenames! This is the cause of many beginners' bugs, because simple concatenation does not handle ...

7 years ago | 0

Answered
storing the index of an Matrix for non zeros
In just two lines, no loop required: >> X = [1,0,2;0,1,1;0,0,4] X = 1 0 2 0 1 1 0 0 ...

7 years ago | 2

| accepted

Answered
I have a problem with fprintf function, MATLAB
You only defined four number conversions within the format string, but you have provided five inputs to fprintf. Start by writin...

7 years ago | 0

| accepted

Answered
How to fix an error in which the system could not read image from folder under loop, using "dir" function?
If you specify the directory for the dir call then you also need to specify it when you read the file: D = '1folder'; S = dir(...

7 years ago | 0

| accepted

Answered
plotting separate parts of a column on different figures
Following your description "I have a large matrix. In the 3rd column, I have my "eta" values. In my 4th column, I have "r" value...

7 years ago | 1

| accepted

Answered
Compare the number of elements in each row of 2 cell arrays (A and B) and determine which array contains minimum number of elements for that row and save them.
Based on the explanation in your comment: isA = ~cellfun('isempty',A); isB = ~cellfun('isempty',B); csA = cumsum(isA,2); csB...

7 years ago | 2

| accepted

Answered
Sum variable size chunks in array
Avoiding duplicating the data in memory (i.e. avoid mat2cell) will probably be faster for larger matrices: fun = @(c){sum(A(:,c...

7 years ago | 1

| accepted

Answered
Why does it seem that the ~isinf(cvx_optval) and co( ~isinf(cvx_optval)) are both not work
"...so theorically,the real answer should be" co= 1 0 1 Nope. You defined co like this: co(bd) = ... where b...

7 years ago | 0

Answered
Unfold 3D Matrix to 2D
Currently the simplest solution is to just use indexing to get the order you want: >> M = reshape(A,3,[]); >> M = M(:,[8,7,4,1...

7 years ago | 0

Answered
Using array values as indices for inserting values into a larger destination array
Use sub2ind: N = 8; R = randi(9,N); % more interesting than MAGIC. C = randi(9,N); % more interesting than MAGIC. V = reshap...

7 years ago | 0

| accepted

Answered
Indice wise reference of indice from another matrix
Use ndgrid and sub2ind: >> A = [0,1;1,1]; >> D = [1,1;2,3]; >> B = zeros(2,2,3); >> S = size(B); >> [R,C] = ndgrid(1:S(1),1...

7 years ago | 0

| accepted

Answered
Convert time to datenum
It is not required to navigate to data directories to read data: D = 'Path of the directory where the MAT files are saved'; S ...

7 years ago | 1

| accepted

Answered
Multidimensional matrix to use for loop
for k = 1:3 X(:,:,k) end If you want to split into a cell array: a = cell(1,3); for k = 1:3 a{k} = X(:,:,k) end ...

7 years ago | 0

Answered
How to make a for loop with matrices using n?
>> n = 10; >> A = toeplitz([2,-1,zeros(1,n-2)]) A = 2 -1 0 0 0 0 0 0 0 0 -1 2 -1 0 0 0 0 ...

7 years ago | 0

| accepted

Answered
Rename a variable using a string
"Rename a variable using a string" Why bother? Both load and save work with scalar structures, which makes your task easy: S =...

7 years ago | 0

| accepted

Answered
Matlab plots my equation wrong
MATLAB has plotted exactly what you asked for, where the y-range ranges over: >> x = -20:0.1:20; >> y = x.^10-1; >> max(y) a...

7 years ago | 1

| accepted

Answered
what does this code represents? and why rand() has no value between parentheses?
It defines a function which returns either 1 or 0, where 1 has ~=20% probability. Simpler code: customer = @()+(rand(1)<=0.2); ...

7 years ago | 0

| accepted

Answered
please in need help , how can i get all the possibile combination 111 112 121 122 211 212 221 222 for matrix A in matlab , than u
>> R = [0.5807,0.5192;0.879,1.5083;0.6836,1.5183] R = 0.5807 0.5192 0.8790 1.5083 0.6836 1.5183 >> [X,Y,Z] = ndgri...

7 years ago | 0

Answered
How can I get and write data from text file?
This code sorts the file data into one cell array C, where each cell in C contains the summer data for one year. The summer star...

7 years ago | 0

| accepted

Answered
Error using cat. Dimensions of arrays being concatenated are not consistent.
That is not very well designed code: the regexp is overkill, and the str2num with cellfun is likely not very efficient (as well ...

7 years ago | 1

| accepted

Answered
Error: Cannot convert double value 5 to a handle
Most likely sch(ii,1), ii, and h are actually all different classes which cannot be concatenated together. You could easily use...

7 years ago | 1

| accepted

Answered
add zero elemant inside cell
Simple indexing does exactly what you need: >> A={[95],[112],[98],[84],[69],[121],[108]}; >> B={[1,2,4],[4,3],[6,9,98],[3,7,88...

7 years ago | 0

| accepted

Answered
How do I find closest values between 2 matrices?
Using basic MATLAB only (i.e. without knnsearch from the Statistics Toolbox): >> true_ang = [-40,-20]; >> all_angs = [30.80304...

7 years ago | 0

Answered
Passing by reference vs value
"Passing by reference vs value" Neither. MATLAB is more intelligent that either of those. MATLAB uses something called "copy on...

7 years ago | 1

| accepted

Answered
Plotting based on a for loop from a cell array
xyz = 'XYZ'; figure() for k = 1:3 subplot(3,1,k) plot(UA_SEG{:,['Acc',xyz(k)]}) end https://www.mathworks.com/help...

7 years ago | 0

| accepted

Load more