Answered
How do I loop trough variables
"Why is that?" Your confusion stems from several things. [] square brackets are a concatenation operator, not a "list" operato...

6 years ago | 0

Answered
How to find the max matrix of a multidimensional matrix array
I suspect that you actually mean that you have a 3D array, in which case you can use max: max(multiarray_star,[],3)

6 years ago | 2

| accepted

Answered
All possible n-length combinations of two numbers
Use ndgrid: (in these examples I used u=5, v=7): [X,Y] = ndgrid([5,7]); % n = 2 M = [X(:),Y(:)] [X,Y,Z] = ndgrid([5,7]); % n ...

6 years ago | 1

| accepted

Answered
Making matrices of different dimensions and clubbing them together
A simple and efficient approach using a cell array: N = number of loop iterations C = cell(1,N); for k = 1:N ... your co...

6 years ago | 0

| accepted

Answered
10 by 10 matrix grid
Use a table: https://www.mathworks.com/help/matlab/tables.html

6 years ago | 1

Answered
Taking 3-D matrices out of a 4-D matrix
Although most likely you would be better off not splitting up your perfectly good numeric array, if you really want to you could...

6 years ago | 0

| accepted

Answered
How to change a function within a loop at certain point in MATLAB
" I tried some stuff with while loops and if statements..." That is entirely the wrong approach in MATLAB. Just use logical ind...

6 years ago | 0

Answered
Coordinates of a 3 by 3 by 3 array
Solution For >2 dimensions you need to use ind2sub (as the find documentation also mentions): >> yy = zeros(3,3,3); >> yy(1,2...

6 years ago | 1

Answered
Saving nonempty columns of cell as separate variables with specific names in matfile
Fake data: >> allad = cell(1,80); >> allad{8} = rand(10000,1); >> allad{25} = rand(5000,1); You can use cell2struct and save...

6 years ago | 1

| accepted

Answered
"V = V.';" What Does This Syntax Mean?
The difference is: ' complex conjugate transpose. .' transpose Several basic numeric operations have two versions, one for l...

6 years ago | 0

| accepted

Answered
how to check if random number is equal to 1
x = [1,3,3]; v = randi(numel(x)); total = total + x(v); if x(v) == 1 r = 1; end

6 years ago | 0

Answered
How to access all elements within a structured cell array without looping?
"I am not using the structure(1).field1 syntax" You should be. It would allow you to use efficient syntaxes for accessing your ...

6 years ago | 1

Answered
How to tell if a value is an integer?
"...which should apply to this since x=1925 ..." Nope. Its actual value is: >> x = 725*(77/29); >> fprintf('%.40f\n',x) 1925...

6 years ago | 1

| accepted

Answered
I want to split cell vector
Using datetime: >> DT = datetime(date,'InputFormat','yyyy-MM-dd'); >> DT.Year ans = 1985 1985 1985...

6 years ago | 0

| accepted

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

Load more