Answered
How to shift entries in a vector by the value of the number in that entry?
T = [0, 0, 4, 0, 7, 0, 0, 5, 0, 9] N = numel(T); X = 1+mod(T+(0:N-1),N); for k = 1:N T([k,X(k)]) = [0,T(k)]; end disp(...

5 years ago | 0

| accepted

Answered
Plot multiple lines from multiple tables
By numbering your variables like that you have made the task a lot harder and more complex. The simpler and much more efficient...

5 years ago | 0

| accepted

Answered
Appending strings to array
"l = zeros(1,length(str)); % defining my empty list " That is not an "empty list": MATLAB does not have a "list" type. It is ...

5 years ago | 1

Answered
How can I remove characters in cvs file?
Using string manipulation: str = fileread('prueba1.csv'); str = strrep(strrep(str,'"',''),';',' '); mat = sscanf(str,'%f',[3,...

5 years ago | 0

| accepted

Answered
add Int8 and int16
add_int(int8(127),int16(129)) function out = add_int(in1,in2) out = int16(in1) + int16(in2); end

5 years ago | 1

Answered
Problems using "datetime" cont.
You should probably specify the input format to match the provided string: S = "12/24/2008 9:59:47 AM.786743640"; D = datetime...

5 years ago | 0

| accepted

Answered
Mean of matrix subarrays without using a loop.
A = [1 0 3 5 0 7; 0 2 6 0 8 0; 3 5 0 0 2 0] B = reshape(A.',3,[]); B(B==0) = NaN; C = reshape(mean(B,1,'omitnan'),[],size(A,1...

5 years ago | 1

| accepted

Answered
Extracting a matrix element which is within a cell containing cells.
Putting scalar numeric data into nested cell arrays is pointlessly complex and inefficient. Get rid of the cell arrays: S = loa...

5 years ago | 0

| accepted

Answered
get specific range of data from vector, indicated by other vector
X = [13500, 14628, 18500, 20788, 24567]; N = numel(X); C = cell(1,N); for k = 1:N Y = (X(k)-3000):X(k); C{k} = data...

5 years ago | 0

| accepted

Answered
how to create a matrix in matlab?
M = dec2bin(0:7)-'0'

5 years ago | 1

Answered
Find a specific char in a cell and turn it into NaN
F = 'UmgebungsmessungDez.csv'; S = detectImportOptions(F, 'Delimiter',';', 'VariableNamingRule','preserve'); X = false(1,numel...

5 years ago | 0

Answered
Move value at index i from one array to another array but at index 3 * i
Robust and reasonably efficient: n = 3; % scale a = 1:3 a(2:n,:) = 0; a = a(1:1-n+end)

5 years ago | 0

Answered
How can I call a matrix entry inside a struct (using sprintf)?
"Since the code is meant to be as short and simple as possible.... Is there any way to utilize the sprintf function or any other...

5 years ago | 0

| accepted

Answered
How to import a text file, including a time column, commas as points, and tabs as delimiters, into workspace as a matrix
F = 'test data.txt'; T = readtable(F, 'Delimiter','\t', 'DecimalSeparator',',', 'VariableNamingRule','preserve')

5 years ago | 1

| accepted

Answered
naming saved files in a for loop
What you wrote: save('savename_masq', 'masqpatient'); What you should write: save(savename_masq, 'masqpatient')

5 years ago | 0

Answered
hex2dec broken in R2020a?
format long str = 'ad55cb92eef08aea93f27c40457f8835'; val = hex2dec(str(01:16))*pow2(64) + hex2dec(str(17:32))

5 years ago | 0

Answered
Numbers as multiply of pi?
atan(sqrt(sym(3))/1)

5 years ago | 1

| accepted

Answered
Using a variable calculated in a function in the workspace
"I thought doing it this way the variable "jobname" is automatically returned to the workspace after the function is done." Nop...

5 years ago | 0

| accepted

Answered
Selective columns from multiple text folders
Here is one simple and efficient approach (untested, but should get you started): P = 'D:\work\1ST EXP\4.2'; V = 0:399; N = n...

5 years ago | 1

| accepted

Answered
Error using function load
load(matfiles(i).) % ^^ You forgot to write the fieldname. Note that you should specify the file extension and f...

5 years ago | 1

| accepted

Answered
How to bold or italicize any sentence or text using fprintf in matlab?
Pure text files do not contain any formatting information: https://www.mathworks.com/matlabcentral/answers/178646-how-to-read-t...

5 years ago | 0

Answered
Coverting specific string containing date to datetime
C = {... '2012_Q4' '2013_Q1' '2013_Q2' '2013_Q3' '2013_Q4' '2014_Q1' '2014_Q2' '2014_Q3' '2014_Q4'}; T = datetime(C, '...

5 years ago | 0

| accepted

Answered
Slow for loop string comparison
I assume that app.ttable.Time is actually a datetime array. In that case, your loop very inefficiently converts each datetime ...

5 years ago | 0

| accepted

Answered
Why is 10^(log10(x)) not x?
"Has anybody an explanation?" The simple explanation is: log10(a) is not exactly representable using a binary floating point nu...

5 years ago | 1

| accepted

Answered
How to remove the unwanted zero at the end in the floating point variable?
"How to remove the unwanted zero at the end in the floating point variable?" Trailing zeros are just an artifact of displaying ...

5 years ago | 0

Answered
Looping to create nested structure?
"...without manually creating a new structure for each time point." Creating individual structures by hand should definitely be...

5 years ago | 0

| accepted

Answered
delete files in folder with different endings
K = [".odb", ".txt", ".py", ".m"]; D = pwd; S = dir(fullfile(D,'*.*')); S = S(~[S.isdir]); % files only for k = 1:numel(S) ...

5 years ago | 0

| accepted

Answered
fprintf is outputting the wrong number, what's wrong with my code?
"what am i doing wrong?" You are printing a character code, not the value of a numeric variable. Replace this: fprintf('the sh...

5 years ago | 1

| accepted

Answered
How could I match data from two files?
T1 = readtable('FILE1.txt', 'ReadVariableNames',false) T2 = readtable('FILE2.txt', 'ReadVariableNames',false) Tout = join(T1,T...

5 years ago | 0

| accepted

Answered
In some specific case, preallocation is slower than doing nothing.
"What did I wrong?" Your timing comparison is 99% meaningless. Your are comparing the times of 100 loop iterations (the i loop...

5 years ago | 1

| accepted

Load more