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...

5 years 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...

5 years 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])

5 years 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...

5 years 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?...

5 years ago | 0

| accepted

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

5 years 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...

5 years 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

5 years 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...

5 years 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...

5 years 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 =...

5 years 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...

5 years 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);

5 years 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...

5 years ago | 1

| 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...

5 years 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...

5 years 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...

5 years ago | 3

| 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...

5 years 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...

5 years 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 ...

5 years ago | 0

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

5 years 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...

5 years 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+\(.+?\)','')

5 years 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...

5 years 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...

5 years ago | 0

| accepted

Answered
i am getting this error on line 26 (fprintf: function is not defined for 'cell' inputs). how to resolve this?
Change these two lines to use curly braces: score = scores{subjectIndex}; % ^ ^ condition = conditions...

6 years ago | 0

Answered
Convert time column from hours to ddmmmyyyy HH:MM:SS
dth = 999312 + [0;1;12;24;36;42;31*24] % fake data dtm = datetime(dth*60*60, 'ConvertFrom','epochtime','Epoch','1900-01-01', 'F...

6 years ago | 0

| accepted

Answered
Help me with for loop
Rather than writing so much code and using numbered variables (very bad data design), you should just use mat2cell: L = rand(46...

6 years ago | 0

| accepted

Answered
While Loop Homework Question
You were close, here is your code with a few small changes: k = 0; a = k; while a<1e6 k = k+1; a = k+a; end disp(...

6 years ago | 0

| accepted

Answered
If statement with an array
Y = max(0,9.1*Y)

6 years ago | 0

Load more