Answered
finding the right values for a vector
Use mrdivide: >> V = (1:15).'; >> a = pi; >> M = a/V M = 0.0025335 0.0050671 0.0076006 0.0101342 0.0126677 0.0...

7 years ago | 1

Answered
get the value of element from matrix
Simply use ismember and basic MATLAB indexing: >> [X,Y] = ismember(B,A(:,1:2),'rows'); >> Z = A(Y(X),:) Z = 9 9 ...

7 years ago | 0

| accepted

Answered
Finding corresponding values in double arrays in structure fields
Note that these methods assume that there is exactly one match per row. If this is not the case, then there is no way to disting...

7 years ago | 2

| accepted

Answered
filling a matrix with a loop
"Does anyone know how to do this?" This is simple and efficient with toeplitz: >> C = [1,zeros(1,399)]; >> R = [1,1,0,1,zeros...

7 years ago | 3

| accepted

Answered
anyway to translate this command using 'cellfun'
Note that it is simpler to use strfind: >> C = strfind(test,'_'); >> C{:} ans = 2 ans = 2

7 years ago | 0

| accepted

Answered
Create a matrix with random integers between 1 and 9
>> reshape(randperm(9),3,3) ans = 6 8 2 3 5 4 7 1 9

7 years ago | 0

| accepted

Answered
Meaning imaginary result of asin(x) function of MATLAB
"'My question is how can we interpret this imaginary number? Does it have any meaning? Yes, it has a meaning. Why does MATLAB ...

7 years ago | 2

Answered
What `gcbf` stands for?
gcbf get callback figure gcbo get callback object These are not necessarily the current ones.

7 years ago | 1

| accepted

Answered
Sorting columns of cell Array
Either download my FEX submission natsort: https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-orde...

7 years ago | 1

| accepted

Answered
the problem of using 'case'
Your first (inadvisable, numerically fragile, should-be-avoided) concept works for me: for omega = 0.1:0.1:2; switch omega ...

7 years ago | 1

| accepted

Answered
Search a matrix combined with logical indexing
>> A = [3,10,2,5;2,14,5,3] A = 3 10 2 5 2 14 5 3 >> N = 10; >> B = A.*(cumsum(A>N,2)>0) B = 0...

7 years ago | 0

| accepted

Answered
Storing multiple value in array without overriding.
"How to avoid that?" Simply by changing the Excel worksheet name on each iteration of the outer loop, e.g.: ... for z=1:nfile...

7 years ago | 0

| accepted

Answered
How to create a for loop through a directory for only certain folders in the directory
An efficient MATLAB solution: P = 'absolute/relative path to the parent directory Sample'; S = dir(fullfile(P,'sub*')); F = {...

7 years ago | 0

Answered
How can I make an array of structs , each struct have a unique index?
"How can I make an array of structs , each struct have a unique index?" Easily: https://www.mathworks.com/help/matlab/matlab_pr...

7 years ago | 0

| accepted

Answered
Regular Expressions using regexp
Matching only integer numbers after 'UZK' or 'T_' (it is unclear in your question if the underscore is permitted or not, but the...

7 years ago | 1

| accepted

Answered
How to read elements from a computed matrix without define a new variable?
MATLAB does not allow indexing into the results of operations. You can either use a temporary variable (which is probably the mo...

7 years ago | 0

| accepted

Answered
Matrix Maipulation and adding from variables in the workspace
Load the file into a variable (which is a structure) and access its fieldnames: S = load(...)

7 years ago | 0

Answered
ERROR-The statement cannot be reached
Those warnings are very simple to understand by aligning the code and looking at the values. MATLAB warns you that lines 14 and...

7 years ago | 2

| accepted

Answered
Using semicolon for input argument when working with a matrix function
" I was thinking concatination, concatinating the same matrix 4 times but multiplying it by 1,2,3, then 4 as requested." It wou...

7 years ago | 2

Answered
Comma separated value to vector
>> S = '11,333,4445,2,78,2399'; >> V = sscanf(S,'%f,',[1,Inf]) V = 11 333 4445 2 ...

7 years ago | 0

| accepted

Answered
Replacing individual Values in Data column based on a condition
idx = myData.fluid_p_rel<0.9 | myData.fluid_p_rel>1.2; myData.fluid_p_rel(idx) = 1

7 years ago | 0

| accepted

Answered
How to convert column datetime to datenum?
It is not clear from your example what class data has: a table or a non-scalar structure or .. ? In any case, datetime objects ...

7 years ago | 1

| accepted

Answered
Error when calling a function : "Dimensions of arrays being concatenated are not consistent."
The full error message is this: Error using vertcat Dimensions of matrices being concatenated are not consistent. Error in fu...

7 years ago | 2

| accepted

Answered
Counting zeros in array
Simpler: >> V = [1,-2,-1,-1,-1,0,0,-1,0,0,0,3,0,0,4,0,0,0,0,0]; >> X = find([V(1:end-1),1]); >> Z = [diff([1,X+1])-1;V(X)].' ...

7 years ago | 3

Answered
Converting binary like table but using decimal values
You can use comma-separated lists on the output of ndgrid: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-li...

7 years ago | 0

| accepted

Answered
How do i compare cell array values and replace with string of code letters?
Method one: >> C = {'UUU','CUU','UUC','UUG'}; >> F = {'UUU','UUC'}; >> L = {'UUA','UUG','CUU','CUC','CUA','CUG'}; >> Xf = is...

7 years ago | 0

| accepted

Answered
How to get nearest values in matrix and save indexes of these values?
>> X = [5,10,15]; >> Y = 0:7/5:30; >> [~,Z] = min(abs(X-Y(:))) % the indices of the closest values: Z = 5 8 12 ...

7 years ago | 2

| accepted

Answered
Operation on structure fields with common part of the field name
S.DUT_2 = 2; S.REF_2 = 3; S.DUT_4 = 4; S.REF_4 = 5; C = fieldnames(S); U = unique(regexp(C,'\d+$','once','match')) F = @(n...

7 years ago | 0

| accepted

Answered
how to change multiple items in a text file?
EDIT: much faster: rpl = '2.5'; % the new value (you can generate this using NUM2STR). str = fileread('bp.txt'); str = strtri...

7 years ago | 0

| accepted

Answered
Extracting numbers from a G-code file
Simple use of one regular expression is all that you need to identify those X, Y, and E values: str = fileread('test.txt'); rg...

7 years ago | 6

Load more