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

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

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

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

5 years ago | 0

| accepted

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

5 years ago | 0

Answered
How can I convert a cell to a matrix ?
The simple and efficient approach: X = reshape([output{:,1}],260,207); y = reshape([output{:,2}],260,207); Z = reshape([outpu...

5 years ago | 0

| accepted

Answered
make matlab read the files in order?
Adapting from the examples in the NATSORTFILES documentation: .. S = dir(fullfile(myFolder,'shape_0*.txt')); S = natsortfiles...

5 years ago | 0

| accepted

Answered
fprfintf for matrices and rounding
A = [1,2,3;4,5,6;7,8,9]; fprintf('%5.2f %5.2f %5.2f\n',A.')

5 years ago | 0

| accepted

Answered
Extracting values from string using regexp
The problem is not extracting the numbers (which is easy) but in knowing which of the numbers has been extracted, which is not a...

5 years ago | 1

Answered
sscanf how to skip lines - not textscan!!!
"Is there a way to skip the first X lines in a text file when reading a text file using sscanf?" No, because sscanf parses stri...

5 years ago | 0

Answered
Find the indices of one variable in another one avoiding NaNs
The C you showed in your example is not possible as it has different numbers of elements in each row, but you could put the data...

5 years ago | 0

| accepted

Answered
Changing variable name within a nested for loop by looping end number in the variable name.
It is very important to learn the correct terminology for your data, because this makes it much much easier to find information ...

5 years ago | 0

| accepted

Answered
How can I read csv file data correctly? I tried multiple ways
textscan has no problems importing the file data simply and efficiently (sample file is attached): opt = {'Delimiter',',','Coll...

5 years ago | 0

| accepted

Answered
Merging two arrays based on index arrays
z_index = [2,3]; y_index = [4,1,5]; z(z_index) = [1,3]; y(y_index) = [-2,4,2]; x(z_index) = z(z_index); % RHS = [1,3] x(y...

5 years ago | 1

| accepted

Answered
Cell 2 Multidimensional Array Conversion
out = permute(cat(3,A{:}),[3,1,2]); https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://www.m...

5 years ago | 0

| accepted

Answered
how to use fprintf in matlab?
"I tried this in matlab and got the same result." The fprintf documentation states that "If you specify a conversion that does ...

5 years ago | 0

Load more