Answered
off value is returned when plugging into function
Your calculator calculated sine using degrees, but MATLAB's sin function uses radians. You will get exactly the same (most like...

6 years ago | 2

Answered
Undefined operator '<' for input arguments of type 'struct'
Explanation This error occurs because GlobalBest.Cost is a structure. Before the loop you defined GlobalBest.Cost to be Inf, s...

6 years ago | 0

| accepted

Answered
Using regular expression to extract numeric data from text file
mat = str2double(vertcat(tokens{:})) You will need to reshape the matrix, e.g.: mat = reshape(mat.',9,[]).' See: https://www...

6 years ago | 0

| accepted

Answered
Find Max of Array of structures.
Where S is your structure: [cnt,idx] = max([S.gold]); S(idx).Countries A comma-separated list is used to concatenate all of t...

6 years ago | 0

Answered
Extract Last two Words from strings in cell
>> A = {'There is a world of good you could perform'; 'All the money in the world couldnot have saved her'; 'W'; 'My world'} A ...

6 years ago | 0

Answered
What does this mean?
The (:) syntax converts an array of any size and number of dimensions into a column vector. So that code calculates the mean of...

6 years ago | 0

Answered
I have a matrix that contains strings and i have to find words in it.
>> mat = ['erduopiece';'tprometall';'isdpstubaa';'gepomsicmv';'steiuratea';'otnncbcbrg';'uefctelule';'vliorbroie';'elenuuirnt';'...

6 years ago | 0

Answered
How to simplify my looping code?
Your code is slow and complex because: you expand all of the arrays xk2, xk3, ... xk208 on every loop iteration, which forces M...

6 years ago | 1

| accepted

Answered
Replacing character between square brackets
>> A = {'[ABC; DEF];[GHI; JKH];'; '[ZBC; YEF];[XHI; UKH];'} A = '[ABC; DEF];[GHI; JKH];' '[ZBC; YEF];[XHI; UKH];' ...

6 years ago | 0

| accepted

Answered
dir sorts filenames wrong
"what can i do?" If the filenames contain sufficient leading zeros, then split the names using fileparts, then sort the names, ...

6 years ago | 0

| accepted

Answered
How can I make my MATLAB code run faster?
Read the advice given here: https://www.mathworks.com/help/matlab/matlab_prog/techniques-for-improving-performance.html In par...

6 years ago | 0

| accepted

Answered
Convert cell array into matrix, but with removing the words, commas, etc
>> ED_array = {'1, thin fin, 1, 2, 7, 8, 0.1, 400.0';'2, thin fin, 2, 3, 6, 7, 0.1, 400.0';'3, thin fin, 3, 4, 5, 6, 0.1, 400.0'...

6 years ago | 0

| accepted

Answered
How generate combination list of 4 independent vectors?
A simple solution for a fixed number of vectors: v1 = [1;2;3;4]; v2 = [5;6;7]; v3 = [8;9]; v4 = [10]; [x1,x2,x3,x4] = ndgr...

6 years ago | 2

| accepted

Answered
Converting a string into a numerical array
Much more efficient than the accepted answer: >> str = '[1,2,3,4,5]'; >> vec = sscanf(str(2:end),'%f,',[1,Inf]) vec = 1 ...

6 years ago | 1

Answered
How to save the value of some variables in a .dat file inside a nested loop in the function environment
Replace "Save Data Here" with: fnm = sprintf('Laser_Like_Hy0=%.12f_Tmax0=%.12f.dat', Hy0(j), Tmax0(i)); mat = [TIME(:), LX(:),...

6 years ago | 1

| accepted

Answered
linprog example returns empty vector (when it should return 0.6667 1.3333)
"...I think it just got installed when I installed certain matlab packages or something." It looks like some badly-written thir...

6 years ago | 0

Answered
How can I use the split function with multiple delimiters?
>> str = 'software_logical/forIteratorSubsystem/Out1'; >> [one,two] = fileparts(str) one = software_logical/forIteratorSubsyst...

7 years ago | 1

| accepted

Answered
Simplify a string with MATLAB script
>> Eq = 'A_1+((A_2+A_3)&(A_4+A_5))+A_6'; >> Fq = regexprep(Eq, '^([A-Z]+_)(.*)', '$1\(${strrep($2,$1,'''')}\)') Fq = A_(1+((2...

7 years ago | 0

| accepted

Answered
How to Set Specific Arg in Function
"I've tried seraching for how to change/edit/give a specific argument but I can't find it. I've tried the following options but ...

7 years ago | 1

| accepted

Answered
How can i extract parameters from a vector at specific values
Use ismember: >> A = 1:10 A = 1 2 3 4 5 6 7 8 9 10 >> B = 11:20 B = 11 12 13 14 1...

7 years ago | 0

| accepted

Answered
Extracting data from strings with varying delimiters and column widths
You can insert delimiters between those numbers, e.g. using regexprep: str = regexprep(str,' *(\d+?) *(\d{1,4}\.\d+)','$1,$2,')...

7 years ago | 1

| accepted

Answered
Simplest way to save a vector to a variable with commas and braces
You can create a character vector: >> strrep(mat2str(a),' ',',') ans = [1,2,3,4,5] which you can save however you want. But t...

7 years ago | 0

| accepted

Answered
Sort certain matrix cells in a vector
Linear indexing: >> G = Start_Matrix([15;16;18;12;13;14]) G = 78.808 83.353 112.37 188.5 ...

7 years ago | 0

Answered
How do I convert strings stored in a cell array to numbers?
Here is a faster solution (which also does not rely of the evil eval hidden inside of str2num): >> C = {'Name','2/8','3/7','7/8...

7 years ago | 1

Answered
Trying to assign into multiple variables using a for loop
Use a cell array: N = s(1,1); C = cell(1,N); for k = 1:N C{k} = news(c,'Symbol',symbol(k),'Category',"Analyst Ratings");...

7 years ago | 1

Answered
combine 30.mat file having 1*15 matrix (Each .mat file having 1 row and 15 columns) to one .mat file
The best approach is to follow the examples in the MATLAB documentation: https://www.mathworks.com/help/matlab/import_export/pr...

7 years ago | 1

| accepted

Answered
Comparing cell with criteria
out1 = cellfun(@(l,r) setdiff(1:9,[l,r]), Spfcfef(:,1), Spfcfef(:,2), 'Uni',0); out2 = cellfun(@(l,r) setdiff(l,r), Spfcf...

7 years ago | 0

| accepted

Answered
Splitting a vector into separate vectors using thresholds
Simpler and more robust: >> x = [9,15,9,23,15,9,15,7,99,0,12] x = 9 15 9 23 15 9 15 7 99 ...

7 years ago | 0

| accepted

Answered
How can I import multiple .CSV files in MATLAB with no sequential filename?
P = 'relative/absolute path to the folder where the files are saved'; S = dir(fullfile(P,'*.csv')); for k = 1:numel(S) F...

7 years ago | 4

| accepted

Answered
Find function in matlab
find returns the indices of non-zero elements of an array. You provided find with a logical array with these values: >> a>10 a...

7 years ago | 2

| accepted

Load more