Answered
how to put the same value in a number of lines in the first column of a matrix and different values in the second column (values coming from vectors)
The simple MATLAB approach is to leverage NDGRID: v1 = 1:1:2; v2 = 1:1:4; [m2,m1] = ndgrid(v2,v1); m = [m1(:),m2(:)] Can be...

5 years ago | 1

Answered
How to input image in array?
The simplest solution is to just store the image data in the same structure that DIR returns: S = dir(fullfile(myFolder,'*.bmp'...

5 years ago | 0

| accepted

Answered
Delete columns in a structure array
Assuming that the data in f10 is scalar numeric (you did not tell us this important information): idx = [Data.f10]>10; Data = ...

5 years ago | 0

| accepted

Answered
Using audioread to read a sequence of files and then combine
Do NOT use EVAL for trivial code like this. Use FULLFILE instead of concatenating text together. P = 'C:\Users\24hr sound anal...

5 years ago | 0

Answered
How to add new cell array into a old struct
[STC_ORE.ore_ton] = ORE_TON{:}; [STC_ORE.x_cent] = X_CENT{:}; [STC_ORE.y_cent] = Y_CENT{:}; [STC_ORE.z_cent] = Z_CENT{:}; ht...

5 years ago | 0

| accepted

Answered
Is there a one-line code for this?
A = [1 1;2 2;3 3;4 4;5 5]; A = [A;A+(0:1)]

5 years ago | 1

| accepted

Answered
replacing a matrix in loop
Do NOT use a loop for this! Do NOT expand any arrays inside loops! A simpler and much more efficient approach using a comma-sep...

5 years ago | 0

Answered
Create a cell array from matrices using for loop
x1 = rand(10,10); y1 = rand(10,10); z1 = rand(10,10); r1 = rand(10,10); a1 = cat(3,x1,y1,z1,r1); x2 = rand(10,10); y2 = ra...

5 years ago | 1

| accepted

Answered
How can I automate the code to run a series of files in a folder?
P = 'G:\.shortcut-targets-by-id\1332UW1v7_g1_AsDgTVQW_dgb0LzbQ4Ni\Elizabeth-Data-Analysis-Spring-2021'; N = 64; % total number ...

5 years ago | 0

| accepted

Answered
For loop getting array name
Your approach is leading you up the garden path. It is simpler to use indexing: P = 'absolute or relative path to where the fil...

5 years ago | 0

Answered
How to convert the values greater than one to less than one for a matrix stored in workspace
M = [1.345, 1.678, 2.345, 3.456, 4.456] M = mod(M,1)

5 years ago | 0

Answered
Can I use randi and say random number from 1 to 30 except 8 and 9? (for example)
This is MATLAB, so your first thought should always be to use arrays and indexing: vec = setdiff(1:30,8:9) % or [1:7,10:30] or ...

5 years ago | 1

| accepted

Answered
How do you align column in a matrix?
Node = [1,0,0,0;2,100,0,0;3,200,0,0;4,33.3333321,0,0;5,66.6666641,0,0;6,133.333328,0,0;7,166.666672,0,0] fmt = '%3d,%13.9g,%13d...

5 years ago | 0

| accepted

Answered
How to separate a string(1x1 cell) into a 1x4 cell
chr = 'A5E6C11D B5E6C11D C5E6C11D D5E6C11D'; spl = split(chr)

5 years ago | 1

| accepted

Answered
combine number from cell array and letter to a string
C = {'3','1','4'} S = join(strcat("V",C),"-") % output = string or the old-fashioned way: S = sprintf('-V%s',C{:}); % output ...

5 years ago | 1

| accepted

Answered
invalid concatenation of structure with matrix
P = fullfile(folderTest,setTestCur); X = {'*.jpg','*.png','*.bmp'}; N = numel(X); C = cell(1,N); for k = 1:N C{k} = di...

5 years ago | 0

| accepted

Answered
ned to turn iterated columns into a single column
Do NOT use EVAL for trivial code like this. Rather than forcing yourself into writing complex, obfuscated code just because you ...

5 years ago | 0

Answered
reshape matrix with variable length to vector
M = [1,2,3;4,5,6;7,8,9] V = reshape(M.',1,[])

5 years ago | 1

| accepted

Answered
How to convert a string into a date or datenum?
"... but i cant, since functions like datetime need the numbers separated." I don't see that restriction mentioned anywhere in ...

5 years ago | 1

Answered
How to read the data from .txt file and plot?
Read the error message and follow its advice to use curly-brace subscripting rather than parentheses: data = readtable('rans1_d...

5 years ago | 1

| accepted

Answered
How to insert data to a matrix based on index values stored in a matrix?
a = randi(9,7,5) b = [2,2,3,1,2;6,5,7,6,5] rwv = 1:size(a,1); idx = rwv(:)<=b(1,:) | rwv(:)>=b(2,:); a(idx) = NaN If you ar...

5 years ago | 0

| accepted

Answered
How to read in more rows to a cell array from a text file?
This would be easier if each block used an integer instead of "First", "Second", etc. By far the best would be leading text foll...

5 years ago | 1

| accepted

Answered
Create a matrix with elements clockwise
More efficient: M = spiral2(5,8)

5 years ago | 1

| accepted

Answered
Why does my V returns a single scalar value?
You are using the wrong divide operator: V=(P*x.^2).*(3*L-x)./(E*I) % ^^ https://www.mathworks.com/help/matl...

5 years ago | 0

| accepted

Answered
Sorting Column Variable to a Row
Do NOT use loops for this, the inbuilt tools are much better! First lets create some fake data in a table: C = randi(6,30,1); ...

5 years ago | 0

| accepted

Answered
Concatenate 2D matrices into one 3D matrix with for loop
C = struct2cell(data); A = cat(3,C{:}); https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://...

5 years ago | 0

Answered
Is there a way to find number of blocks in a matrix?
Assuming that the blocks do not contain zeros: A = [1,2,0,0,0,0,0,0,0;3,4,5,6,0,0,0,0,0;0,7,8,9,0,0,0,0,0;0,1,2,3,4,5,0,0,0;0,0...

5 years ago | 0

| accepted

Answered
Arrange array elements in 1st column w.r.t corresponding values in 2nd column
A = [1,9;1,14;3,11;5,13;7,15;9,17;11,19;14,21] B = myfun(A) function out = myfun(inp) out = []; while numel(inp) vec ...

5 years ago | 0

| accepted

Answered
Find order of increasing integers
V = [3,4,8,9,10,13]; D = diff(find([true,diff(V)~=1,true])); C = mat2cell(V,1,D)

5 years ago | 0

| accepted

Answered
How to specify index variable name of for loop programmatically?
"Is there a cleaner way to rethink this problem?" Of course. Using MATLAB effectively means using arrays and indexing. Note th...

5 years ago | 1

| accepted

Load more