Answered
Display double number with 6 digits exactly
sprintf('The number is %#.6g', 12.45) sprintf('The number is %#.6g', 2)

ungefär 2 månader ago | 1

| accepted

Answered
readtable to specify date format to avoid ambiguity on a single variable in file.
As the warning (it is not an error) message shows, set "inputFormat" (not "datetimeFormat"): FILENAME = 'testData.csv'; opts =...

ungefär 2 månader ago | 0

Answered
convert exp number to datetime
N = 2.022051711034598e+16; S = string(uint64(N)) D = datetime(S, 'inputFormat','uuuuMMddHHmmssSSS', 'Format','yyyy-MM-dd HH:mm...

ungefär 2 månader ago | 1

| accepted

Answered
conver catagorical to juliandate
C = categorical({'2021-08-22','2021-08-21','2021-08-23','2021-08-22'}) double(C) % get the category indices S = string(C) % ge...

ungefär 2 månader ago | 0

| accepted

Answered
Changing file path in a loop and save figures
As I wrote earlier, you need to get DIR to more of the work for you. It is simpler and much more efficient when you let DIR do a...

ungefär 2 månader ago | 0

Answered
Keep a tally of the number of occurences of a value in an array
A = [2,3,1,2,1,4,3,2,4]; % method 1 F = @(n)nnz(A(1:n)==A(n)); B = arrayfun(F,1:numel(A)) % method 2 B = sum(triu(A==A.'),1...

ungefär 2 månader ago | 0

| accepted

Answered
Add value in vector and use it as input for the next row
S = [1,1,1,0,1,0]; E = [4,2,5,10,2,3]; k = 10; X = S==1; Z = S; Z(X) = k+cumsum(E(X))

ungefär 2 månader ago | 0

| accepted

Submitted


Maximally Distinct Color Generator
Generate maximally distinct colors in an RGB colormap.

ungefär 2 månader ago | 28 downloads |

Thumbnail

Answered
Get all files under a folder
Just filter out the folders afterwards: P = uigetdir(pwd,'Select a folder'); S = dir(fullfile(P,'*')); S([S.isdir]) = [] % re...

ungefär 2 månader ago | 0

| accepted

Answered
how to split a string (char value) with zero in front of it but showing the value in the matrix?
S = '0100'; V = sscanf(S,'%1u')

ungefär 2 månader ago | 1

| accepted

Answered
Add indicative labels to vector values
A1 = [1;2;3]; A2 = [4;5;6]; A1(:,2) = 0; A2(:,2) = 1; A = [A1;A2]

ungefär 2 månader ago | 0

Answered
multiplication of a 3-D matrix by a 1-D array
You don't need a special kind of multiplication, you just need to match the vector orientation to the array: C = A .* reshape(B...

ungefär 2 månader ago | 0

| accepted

Answered
Find index of a structure with multiple conditions of multiple fields
S.liste.a = linspace(1,30,5); S.liste.b = linspace(1,60,5); S.liste.c = linspace(1,80,5); X = S.liste.a<10 & S.liste.b<50 & S...

ungefär 2 månader ago | 0

| accepted

Answered
Retrieve multiple fields with similar names from a struct
Instead of forcing meta-data (i.e. pseudo-indices) into the fieldnames, why are you not simply using a non-scalar structure? The...

ungefär 2 månader ago | 1

| accepted

Answered
Making Matrix dimensions agree
x=-2:0.04:2; y=-4:0.04:4; [X,Y] = meshgrid(x,y); fXY = X.*exp((-X.^2)-(Y./2).^2); % use X and Y here, not x and y. surf(X,Y,...

2 månader ago | 2

| accepted

Answered
Merge rows of cell array with strings per column?
C = {'A','C'; 'B','D'} D = cellfun(@(c)join(c,''),num2cell(C,1)) D = cellfun(@(c)[c{:}],num2cell(C,1),'uni',0)

2 månader ago | 0

| accepted

Answered
How do I split a vector into parts using indexes?
x = 1:100; y = [10,40,60]; C = mat2cell(x(1:y(end)),1,diff([0,y]))

2 månader ago | 0

| accepted

Answered
Could not recognize the format of the date/time text
C = ["07/04/2021 07:55:27.502.118" "07/04/2021 07:55:27.502.196" "07/04/2021 07:55:27.502.274" "07/04/2021 07:55:...

2 månader ago | 0

| accepted

Answered
extract number of columns in each row
Where C is your cell array: V = cellfun(@numel,C) V = cellfun('size',C,2)

2 månader ago | 1

| accepted

Answered
Function that outputs a varying number of variables depending on input --> N inputs = N output variables
"To my understanding I would be unable to use alternate methods given that the data I am loading are mutlidimensional arrays of ...

2 månader ago | 0

| accepted

Answered
To write a For loop in which a variable is updated with each run.
"I want to make this more efficient by using a for loop (if it can be done)." Of course it can be done, you just need to avoid ...

2 månader ago | 0

| accepted

Answered
Using an array as an element in a function.
Use element-wise division ./ not matrix division / You will probably also need to use element-wise power .^, not matrix power ^...

2 månader ago | 0

Answered
create cell array by extracting all the same row from multiple matrix
"Is this achievable through cellfun?" Yes: A = rand(105,3); B = rand(105,3); C = rand(105,3); D = cellfun(@vertcat,num2cell...

2 månader ago | 0

| accepted

Answered
I want to enter a mathematical function as an argument to a function
The simple approach using a function handle: plot_compare(@sin , 5 ,20); plot_compare(@(t) 4*t+9 , 5 ,20); function plot_co...

2 månader ago | 0

| accepted

Answered
How to create a table from strings and numerical data?
" I don't want to preallocate anything as the sizes are unknown. I wanna start with an empty table and then after first iteratio...

2 månader ago | 0

Answered
Plot the last value from each cell from excel file
"Could you please provide me the best way to extract the last values in each cell and plot it?" Sure, I already did that sixtee...

2 månader ago | 0

| accepted

Answered
Alternative to Eval for small number of variables
Approaches like EVAL and structure fields for this task are far too complex. You need to learn how to use arrays to write simpl...

2 månader ago | 0

Answered
Convert input item into string
https://www.mathworks.com/help/matlab/ref/inputname.html

2 månader ago | 1

| accepted

Answered
Extract value until regexp case match
Does the data you want to match always occur at the start of the string? A = "9/12/2022 7:38:51 PM 216 Indicator"; B = regexp(...

2 månader ago | 1

| accepted

Answered
Sine Function I'm trying to Plot won't show up
"Not sure what I'm doing wrong here." You need to use element-wise division, not matrix division: phi = 0:0.1:6*pi; I2 = sin(...

2 månader ago | 1

| accepted

Load more