Answered
Storing Multiple Arrays into Larger Array
This is easy if you store all of the data in one cell array (rather than in separate variables): C = {a,b,c,..,p}; % this is ho...

13 days ago | 0

| accepted

Answered
delete zero elements from vector
k = nonzeros(k); k(end+1:end+2) = k(end)

13 days ago | 0

| accepted

Answered
How to create multiple arrays for multiple outputs of a function in a for loop
In MATLAB it is generally much better to loop over indices, rather than looping over data values: dt = 1e-6; D_targ = 100; v_...

13 days ago | 0

Answered
For loop help!
"... so becase of the amount of data i need a for loop" I doubt that using a loop would be a good approach. V = 1:12; R = 3; ...

13 days ago | 0

Answered
Convert Array of Float to comma delimited string
data = [1,2,3,4]; strjoin(compose("%d",data),", ") % provides formatting control strjoin(""+data,", ") % default formatting

15 days ago | 1

| accepted

Answered
How to extract output from function
To get De you could use arrayfun: a=1; b=2; ya=1; m=40; [t,y]=pure(@my,a,b,ya,m) [~,dE] = arrayfun(@(tv)my(tv,y),t) funct...

15 days ago | 0

| accepted

Answered
Dynamic variable names for MATLAB table
Use array2table instead of table (the wrong function, unless you really want the array in one variable). Get rid of all of that...

15 days ago | 0

| accepted

Answered
Creating Diagonal Matrix from a Vector
The efficient MATLAB approach: g = [1,2,3,4,5]; z = zeros(1,numel(g)-1); m = toeplitz([g(1),z],[g,z])

15 days ago | 0

| accepted

Answered
Error when accessing indices of a vector
Is zero a valid index? n = 2; i = 262140; mod(i+n+1, 262143) Solution: to adjust from zero-based indexing (shown in the prov...

16 days ago | 1

| accepted

Answered
Iterate through several tables of different sizes to perform calculations separately
"Is it possible to loop through them or do I need to create a pointer to each table? Is a pointer to a table possible in matlab?...

17 days ago | 0

| accepted

Answered
two outputs of a function
[cnt,A] = matrice_nou_vechi([1,2],3,2)

18 days ago | 0

| accepted

Answered
find distances between vectors in a cell array
"pdist doesnt seem to work for me in this case bc the elements arent character arrays or strings." According to the pdist docum...

19 days ago | 0

Answered
How to replace different values with NaN in a matrix.
Matrix = [50 51 52 53 54 55; 110 111 112 113 114 115; 1 0 0 1 0 0].' idx = Matrix(:,3)==0; Matrix(idx,2) = NaN

20 days ago | 0

Answered
Error using == Matrix dimensions must agree.
You don't need a loop, try this: idx = cellfun(@isempty,combined1); combined1(idx) = [] "Anyone who can spot the mistake?" Y...

20 days ago | 0

| accepted

Answered
I don't know how to use the correct command in MATLAB
"Probably there is a problem with the command" No, as the error message states there is a problem with the orientation of the f...

20 days ago | 0

Answered
How to combine struct names based on the first 'n' characters of name
One approach: fnm = {'Object1_test1.xls','Object1_test2.xls','Object2_test1.xls','Object3_test1.xls'}; val = [3,6,4,5]; tmp =...

20 days ago | 0

Answered
Access to nested structs
Use getfield with a comma-separated list: a.b.c.d = pi; x = {'b','c','d'}; getfield(a,x{:}) https://www.mathworks.com/help/m...

20 days ago | 1

| accepted

Answered
Have an array of 16 values, want to output them in order value by value, with the same string of text before each value
The simple and efficient MATLAB approach is to use fprintf: amount = [0,2,3,5,13,7]; fprintf('The amount is %d\n',amount);

20 days ago | 0

| accepted

Answered
character vector vs scalar string (size comparison).
The string class is basically a fancy container class for character vectors. That is to say, inside every string element is a ch...

21 days ago | 0

| accepted

Answered
find and replace matrix according vector
x = [1,2,3,7,8,9,13,22,30]; A = [1,3,6,9;2,12,13,8;3,3,6,7;4,22,31,30;5,8,9,33]; ida = ismember(A,x); ida(:,1) = false; A(id...

21 days ago | 1

Answered
Fast calculation of min for a cell array?
nc = size(A,2); Amin_value = cell(1,nc); Amin_row = cell(1,nc); for k = 1:nc [Amin_value{1,k},Amin_row{1,k}] = min(A{3...

21 days ago | 0

| accepted

Answered
Operator '-' is not supported for operands of type 'table'.
Assuming that data is your table, then you need to use the correct type of indexing: () parenthese returns a sub-table of the t...

21 days ago | 1

| accepted

Answered
How to do input correctly
Metal = input('Choose a metal material:','s'); switch Metal case 'AISI1020' S_y = 427; G = 80.000; % dec...

22 days ago | 0

Answered
efficient loop - finding min and max index of certain value
Assuming that each value occurs only within one contiguous block: ic = [1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;3;3;3;3;3;60000;60000;600...

22 days ago | 0

| accepted

Answered
Extract variable from .mat files
D = 'absolute/relative path to the folder where the files are saved'; S = dir(fullfile(D,'*.mat')); for k = 1:numel(S) F ...

22 days ago | 0

Answered
can I use switch case for strings?
c=input('kelvin,celsius,fahrenheit ','s'); % ^^^^ you need this option!

22 days ago | 0

| accepted

Answered
interp2 for values in a matrix with NaN values
Either way you need to extrapolate scattered data (your data are scattered because the NaN are missing data). This page explains...

22 days ago | 0

Answered
how to remove a part which has specific char in the beginning and in the end in string?
str = 'cat dog zebra (squirrel) fish'; out = regexprep(str,'\s+\(.+?\)','')

22 days ago | 0

| accepted

Answered
Import all Files of one folder in order
If you just want an alphanumeric sort of the filenames then you can download my FEX submission: https://www.mathworks.com/matla...

23 days ago | 1

Answered
How can I use the unique function to output all the different numbers following M from all the file names?
I doubt that you need a loop. You could use a simple regular expression to get the required digits, e.g.: D = '/Users/apple/Des...

23 days ago | 0

| accepted

Load more