Answered

Shorten description of multiple fields and values in struct

Either use CELL2STRUCT: % Fake data: Varnames = cellstr("X"+(1:18)); VarDec = randi(9,5,3,18); % Convert to struct: C = num...

Shorten description of multiple fields and values in struct

Either use CELL2STRUCT: % Fake data: Varnames = cellstr("X"+(1:18)); VarDec = randi(9,5,3,18); % Convert to struct: C = num...

25 dagar ago | 1

| accepted

Answered

replace values in char array if conditions are met

C = {'00','15','30','45','00','15','30','45'}; V = str2double(C)/60; V = V+cumsum([0,diff(V)<0])

replace values in char array if conditions are met

C = {'00','15','30','45','00','15','30','45'}; V = str2double(C)/60; V = V+cumsum([0,diff(V)<0])

25 dagar ago | 0

Answered

Turning 2D array (58x23) into 4D array (58x1x23x1)

"I can't get any further than the above dimensions" It is not clear what the problem is: are you expecting trailing singleton d...

Turning 2D array (58x23) into 4D array (58x1x23x1)

"I can't get any further than the above dimensions" It is not clear what the problem is: are you expecting trailing singleton d...

26 dagar ago | 1

| accepted

Answered

How to check if a variable exists and if yes display the variable.

"Why can't I check if this exists?" Of course you can, you just need to use function syntax and not command syntax: https://ww...

How to check if a variable exists and if yes display the variable.

"Why can't I check if this exists?" Of course you can, you just need to use function syntax and not command syntax: https://ww...

26 dagar ago | 1

Answered

Replace negative values with zero and values above 1 with 1, using loop in a 8760 x 1000 matrix

Much simpler and more efficient than using loops, where A is your array: ltz = sum(A<0,1); gto = sum(A>1,1); B = max(0,min(1,...

Replace negative values with zero and values above 1 with 1, using loop in a 8760 x 1000 matrix

Much simpler and more efficient than using loops, where A is your array: ltz = sum(A<0,1); gto = sum(A>1,1); B = max(0,min(1,...

26 dagar ago | 3

Answered

Common substring index from two string arrays

a = ["frame01", "frame02", "frame03"]; b = ["capture00.jpg", "capture01.jpg", "capture02.jpg", "capture03.jpg", "capture04.jpg"...

Common substring index from two string arrays

a = ["frame01", "frame02", "frame03"]; b = ["capture00.jpg", "capture01.jpg", "capture02.jpg", "capture03.jpg", "capture04.jpg"...

26 dagar ago | 0

| accepted

Answered

less than against less or equal than

"Can someone tell me what is going on" Exactly as the comparison tells you, the value stored in that variable is greater than t...

less than against less or equal than

"Can someone tell me what is going on" Exactly as the comparison tells you, the value stored in that variable is greater than t...

26 dagar ago | 0

| accepted

Answered

Array prealocation - Extra array of zeros in 3D array

windows3D = nan(2000,5147,0); or use actual preallocation: N = size(eegDataNorm,1); windows3D = zeros(2000,5147,N); for k = ...

Array prealocation - Extra array of zeros in 3D array

windows3D = nan(2000,5147,0); or use actual preallocation: N = size(eegDataNorm,1); windows3D = zeros(2000,5147,N); for k = ...

26 dagar ago | 0

| accepted

Answered

How to convert a char array field in a struct array to a string field in a vectorized fashion.

S = struct('code',{'CO128','TX457'}); S.code % checking tmp = num2cell(string({S.code})); [S.code] = tmp{:}; S.code % checki...

How to convert a char array field in a struct array to a string field in a vectorized fashion.

S = struct('code',{'CO128','TX457'}); S.code % checking tmp = num2cell(string({S.code})); [S.code] = tmp{:}; S.code % checki...

30 dagar ago | 0

| accepted

Answered

Create a matrix using rand function with a value range

0.004*rand(50,50)

Create a matrix using rand function with a value range

0.004*rand(50,50)

ungefär en månad ago | 0

| accepted

Answered

for loops and storing values

"what can i do to solve this?" Use indexing into a preallocated array: c = nan(46,4); % <--- preallocate! for h = 1:23 f...

for loops and storing values

"what can i do to solve this?" Use indexing into a preallocated array: c = nan(46,4); % <--- preallocate! for h = 1:23 f...

ungefär en månad ago | 1

Answered

I am getting error

You need to use array operations, not matrix operations (you missed this for multiplication): https://www.mathworks.com/help/ma...

I am getting error

You need to use array operations, not matrix operations (you missed this for multiplication): https://www.mathworks.com/help/ma...

ungefär en månad ago | 0

Answered

Error with matrix "Error using vertcat" Dimensions of arrays being concatenated are not consistent.

The problems are on these lines: 0 0 0 0 -1 0 1 0 0 mp*AG4x-Fp4x(1,i) 0 0 0 0 0 -1 0 1 0 mp*AG4y-Fp4y(1,i) Because AG4x and A...

Error with matrix "Error using vertcat" Dimensions of arrays being concatenated are not consistent.

The problems are on these lines: 0 0 0 0 -1 0 1 0 0 mp*AG4x-Fp4x(1,i) 0 0 0 0 0 -1 0 1 0 mp*AG4y-Fp4y(1,i) Because AG4x and A...

ungefär en månad ago | 0

| accepted

Answered

How to normalize only one column of a matrix

normalize(X(:,2),'range',[0,1]) or simply rescale(X(:,2)) If you want to replace the data in the matrix then allocate the fun...

How to normalize only one column of a matrix

normalize(X(:,2),'range',[0,1]) or simply rescale(X(:,2)) If you want to replace the data in the matrix then allocate the fun...

ungefär en månad ago | 0

| accepted

Answered

I need to write a code to import multiple csv files, changing delimiter and decimal standard...

Use READMATRIX and set the Delimiter and DecimalSeparator to values that suit your file.

I need to write a code to import multiple csv files, changing delimiter and decimal standard...

Use READMATRIX and set the Delimiter and DecimalSeparator to values that suit your file.

ungefär en månad ago | 0

| accepted

Answered

merging workspace from different .mat files

"I think the problem ive run into is my files contain the same variable names..." That is not a problem at all, actually that i...

merging workspace from different .mat files

"I think the problem ive run into is my files contain the same variable names..." That is not a problem at all, actually that i...

ungefär en månad ago | 0

| accepted

Answered

Why doesn't this function declaration work?

You are missing a closing parenthesis here: concentrations(n-i-1) = maxconc*(1/factor^(i-1); % ...

Why doesn't this function declaration work?

You are missing a closing parenthesis here: concentrations(n-i-1) = maxconc*(1/factor^(i-1); % ...

ungefär en månad ago | 1

| accepted

Answered

Using sprintf to match the results of format

Introduced in R2021a: https://www.mathworks.com/help/matlab/ref/formatteddisplaytext.html format short str = strtrim(formatted...

Using sprintf to match the results of format

Introduced in R2021a: https://www.mathworks.com/help/matlab/ref/formatteddisplaytext.html format short str = strtrim(formatted...

ungefär en månad ago | 0

Answered

How to code with for loop loops without using ndgrid?

As this is clearly homework, this should get you started: inp = {1:2, 3:4, 5:6}; [A,B,C] = ndgrid(inp{:}); A1=reshape(A,[],1)...

How to code with for loop loops without using ndgrid?

As this is clearly homework, this should get you started: inp = {1:2, 3:4, 5:6}; [A,B,C] = ndgrid(inp{:}); A1=reshape(A,[],1)...

ungefär en månad ago | 0

Answered

Expected Behavior for contains()?

Exactly as its documentation explains, CONTAINS returns a logical TRUE where pat (second input) is found anywhere within the str...

Expected Behavior for contains()?

Exactly as its documentation explains, CONTAINS returns a logical TRUE where pat (second input) is found anywhere within the str...

ungefär en månad ago | 0

| accepted

Answered

How to perform operations on time matrices

a = [0,2.3450,3.4570;1,3.4670,4.8750;2,4.6350,5.8350] m = a(:,2:end)-mean(a(1,2:end)); [~,x] = sort(m<0,1); for k = 1:size(m,...

How to perform operations on time matrices

a = [0,2.3450,3.4570;1,3.4670,4.8750;2,4.6350,5.8350] m = a(:,2:end)-mean(a(1,2:end)); [~,x] = sort(m<0,1); for k = 1:size(m,...

ungefär en månad ago | 0

| accepted

Answered

Operate by logical arrays element by element (error: Unable to perform assignment because the left and right sides have a different number of elements.)

a = [1,nan]; b = [8,9]; x = isnan(a); a(x) = b(x)

Operate by logical arrays element by element (error: Unable to perform assignment because the left and right sides have a different number of elements.)

a = [1,nan]; b = [8,9]; x = isnan(a); a(x) = b(x)

ungefär en månad ago | 0

| accepted

Answered

Finding consecutive zeros in an array. Not able to solve using diff command

a = [0,0,1,1,-1,0,0,0,1,1,1,-1,0,0,1,-1]; d = diff([false,a==0,false]); b = find(d>0); e = find(d<0); m = max(e-b)

Finding consecutive zeros in an array. Not able to solve using diff command

a = [0,0,1,1,-1,0,0,0,1,1,1,-1,0,0,1,-1]; d = diff([false,a==0,false]); b = find(d>0); e = find(d<0); m = max(e-b)

ungefär en månad ago | 0

| accepted

Answered

Incorrect results from intersect when entering imaginary numbers

A = readmatrix('data1.txt') B = readmatrix('data2.txt') C = intersect(A,B,'rows')

Incorrect results from intersect when entering imaginary numbers

A = readmatrix('data1.txt') B = readmatrix('data2.txt') C = intersect(A,B,'rows')

ungefär en månad ago | 0

Answered

Trouble Reading Multiple .csv Files. "Intermediate dot '.' indexing produced a comma-separated list..." Error.

DataID(i).AxialStrain = DataID(i).RawData(1:ending,1); % ^^^ you need this index every time you ref...

Trouble Reading Multiple .csv Files. "Intermediate dot '.' indexing produced a comma-separated list..." Error.

DataID(i).AxialStrain = DataID(i).RawData(1:ending,1); % ^^^ you need this index every time you ref...

ungefär en månad ago | 1

| accepted

Answered

loop on handles on GUI

fnm = sprintf('checkbox%d',i); handles.(fnm)

loop on handles on GUI

fnm = sprintf('checkbox%d',i); handles.(fnm)

ungefär en månad ago | 1

| accepted

Answered

how to read files with different name using fid

fnm = sprintf('pfoil_1_var_1_%d.raw',i); fid = fopen(fnm,'r');

how to read files with different name using fid

fnm = sprintf('pfoil_1_var_1_%d.raw',i); fid = fopen(fnm,'r');

ungefär en månad ago | 1

| accepted

Answered

Sorting Nested Structures based on Name

As far as I can tell, your actual goal is to sort the elements of all structures based on the content of their NAME field. Assu...

Sorting Nested Structures based on Name

As far as I can tell, your actual goal is to sort the elements of all structures based on the content of their NAME field. Assu...

ungefär en månad ago | 0

| accepted

Answered

Find the index of an interval of values in cell array

index = cellfun(@(x) 500<x & x<956, SS, 'uniform', false);

Find the index of an interval of values in cell array

index = cellfun(@(x) 500<x & x<956, SS, 'uniform', false);

ungefär en månad ago | 0

Answered

Replace comma with dot after fopen

fnm = 'trial_file.txt'; opt = detectImportOptions(fnm, 'VariableNamesLine',9, 'VariableUnitsLine',10, 'DecimalSeparator',',', '...

Replace comma with dot after fopen

fnm = 'trial_file.txt'; opt = detectImportOptions(fnm, 'VariableNamesLine',9, 'VariableUnitsLine',10, 'DecimalSeparator',',', '...

ungefär en månad ago | 1