Answered
Strange behavior of "sort" function
Your first example is just a coincidence, but that is NOT the correct way to get the original vector order. The correct way to ...

6 years ago | 1

| accepted

Answered
Delete and replace a struct in a mat file
You can simply use the -append option, e.g. where var is the variable that you want to replace: var = [...]; fnm = 'name of th...

6 years ago | 0

Answered
Fzero using for loop
You need to parameterize the function: https://www.mathworks.com/help/matlab/math/parameterizing-functions.html Note that it i...

6 years ago | 0

| accepted

Answered
how to use function "find" over matrices
"find the first value in each column which lis ess than 0.25 but greater than 0.2." >> x = rand(13,7) x = 0.833676 0.654...

6 years ago | 1

| accepted

Answered
Struct to numeric variable
Apparently you have a 446x1 or 1x446 structure array, where the field in question contains a row vector. To concatenate all of t...

6 years ago | 0

| accepted

Answered
How to raise a decimal numbers as power of A??
Either use a loop or cellfun: >> A = [1,5,3;4,5,9;7,8,9]; >> V = 0.1:0.11:10; >> C = arrayfun(@(n)A^n,V,'uni',0); And checki...

6 years ago | 1

Answered
How to find and replace the content of an array
>> C = {'03/07/2019' '03/07/2019 00:30:00'}; >> X = cellfun('length',C)==10; >> C(X) = strcat(C(X),' 00:00:00') C = 03/07/2...

6 years ago | 0

Answered
How to load files in order
Use either of the methods shown in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of...

6 years ago | 0

| accepted

Answered
How to create an array with repeating values of a vector
m = repmat(v,20,1) or m = v(ones(1,20),:) or m = ones(20,1)*v or m = zeros(20,1)+v % requires >=R2016b or [~,X] = ndgrid...

6 years ago | 1

| accepted

Answered
Function like "find" but for lines
>> B = find(A.').' B = 1 2 4 5 6 9 11 12

6 years ago | 1

| accepted

Answered
How can I remove identical cell entries containing small arrays
Two efficient loops, no third-party functions: S = load('example.mat'); C = S.connect_group; N = numel(C); X = true(1,N); f...

6 years ago | 1

| accepted

Answered
Matrix split in vector
>> B = nonzeros(A.') B = 1 2 3 4 5 6 7 8

6 years ago | 0

| accepted

Answered
Import data as a structure array from a text file with different titles in the middle.
opt = {'MultipleDelimsAsOne',true}; out = {}; [fid,msg] = fopen('datafile.txt','rt'); assert(fid>=3,msg) while ~feof(fid) ...

6 years ago | 0

| accepted

Answered
Generate multiple matrices based on multiple inputs
P = 'Select which type(s) you would like: 1, 2 or 3. For multiple, seperate numbers with a space.'; C = inputdlg(P); V = sscan...

6 years ago | 1

| accepted

Answered
How to convert string "26/7" into a double variable?
>> str = '26/7'; >> vec = sscanf(str,'%f/%f'); >> vec(1)./vec(2) ans = 3.7143 One line (but I would not recommend using thi...

6 years ago | 2

Answered
How to save cell array of workspace vars into mat?
save('test.mat', vars{:}) How it works: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://...

6 years ago | 1

| accepted

Answered
Simple Matrix Reduction Question. Ones and Zeros.
Simpler: >> [B,~] = find(A.') B = 4 1 2 3

6 years ago | 1

Answered
How do I match nested parenthesis (brackets, or braces) with dynamic regular expressions?
This matches the outer-most matched pair of parentheses: >> str = 'asdf (( dwer e: ( asdedsdskek))::)asd fg ( qwe 4 dfy5 57) q3...

6 years ago | 4

| accepted

Answered
Converting txt file string to matrix.
>> str = '{co-ordinates 1.5 2.5 4.8 weighting 11.7}{co-ordinates 2.5 2.8 1.7 weighting 21.4}{co-ordinates 1.5 2.5 4.8 weig...

6 years ago | 0

| accepted

Answered
I am trying to run this script, but it only returns the last part of the switch- the otherwise part, please help...
Your switch condition will not work as you expect. If you want to use logical comparisons for the case values, then you will nee...

6 years ago | 0

Answered
Calling a nested function from a dynamic regular expression throws an error
The best and most general workaround I have found so far is to call regexp from a local function, with function handles to the n...

6 years ago | 0

Answered
how to center a string
str = '23'; num = 9; tmp = (num-numel(str))/2; out = sprintf('%*s%*s',fix(tmp)+numel(str),str,ceil(tmp),'')

6 years ago | 0

Answered
Asking about an output
"My question is why the term 1.0e-05 * appearing?" Because you are displaying the values in the command window using long forma...

6 years ago | 0

| accepted

Answered
How to filter a structure array based on a numeric value from a field?
You will need to concatenate the comma-separated list into one numeric array, e.g.: trips([trips.dir_id] == 1); % ^ ...

6 years ago | 1

| accepted

Answered
how would I add several matrices into one? (assembling global stiffness matrix for FEA)
This is easy when you store all of the matrices in one cell array, then you just need a simple for loop: >> C = {[1,1;1,1],[1,1...

6 years ago | 1

| accepted

Answered
Adding numbers in array in a specific order
>> [~,~,X] = unique(a); >> d = accumarray(X(:),b(:)) d = 81 122 245 985 2663

6 years ago | 0

| accepted

Answered
How can I sample n elements from each column of a matrix?
>> X = sub2ind([4,5],randi(4,2,5),[1:5;1:5]); >> B = A(X) B = 3 8 9 13 20 3 7 10 15 20

6 years ago | 0

Answered
How to call a function
Make these changes: clear,clc,close all % <-------- DELETE THIS AWFUL ANTIPATTERN LINE OF EVIL function [C1, C2, C3, C4, C5, s...

6 years ago | 0

| accepted

Answered
Passing extra output arguments from ode
"In summary my question is, how do I obtain f for the same time instants at which x is obtained." Using a persistent variable o...

6 years ago | 1

| accepted

Answered
why matlab always show my equation as matrix dimension
Most likely you need to follow the advice given in the error message and use array operations, e.g.: y = (668.061./x).*(-39-exp...

6 years ago | 0

Load more