Answered
Can you use the 'format long' command in the 'fprintf' command?
"Can 'format long' be used in fprintf?" No. "If not, how can I keep the numbers in front of the decimal place the same length....

6 years ago | 1

| accepted

Answered
How to replace every other element in an array with a different number
>> V = 200:-2:0; >> V(2:2:end) = -V(2:2:end)

6 years ago | 1

| accepted

Answered
Converts a string into a function to plot
Use https://www.mathworks.com/help/matlab/ref/str2func.html >> equ = 'sin(x)'; >> fun = str2func(sprintf('@(x)%s',equ)); >> f...

6 years ago | 0

| accepted

Answered
How to replace multiple values with the same value in a cell array?
The RHS must be a scalar cell. The LHS must use parentheses, because you are replacing cells (not accessing their contents). o...

6 years ago | 0

| accepted

Answered
neat stacking of array and cell array
Where C is your cell array: D = C.'; D(cellfun(@isempty,D)) = []; % not actually required: try without it! M = vertcat(D{:}) ...

6 years ago | 1

| accepted

Answered
how to store a value in the next row?
The MATLAB approach: >> [X,Y] = ndgrid(0:0.2:1); >> M = [Y(:),X(:)] M = 0.00000 0.00000 0.00000 0.20000 0.000...

6 years ago | 0

Answered
Extract data from a .mat file entred by the user
"...one idea is to do this " You just need to use dynamic fieldnames: https://www.mathworks.com/help/matlab/matlab_prog/genera...

6 years ago | 0

Answered
How to copy a part of characters from each cell to a new matrix?
This is most likely the fastest way to convert to numeric: >> inp = {'1601|192(24.7°|28.5TM°)','983|741(6.85°|276.53TM°)','1114...

6 years ago | 1

| accepted

Answered
Counting by One, placing it in a string
>> n0 = 5; >> n = 10; >> c = sprintf(',%d',n0+(0:n-1)); >> c = c(2:end) c = 5,6,7,8,9,10,11,12,13,14

6 years ago | 0

| accepted

Answered
Calling different file names and plotting them
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html for k = 1:11 F = sprintf('G%d.mat',k)...

6 years ago | 1

| accepted

Answered
How to append a text file to another text file
Assuming no trailing newline characters in the files, perhaps one of these: Append to existing file: st2 = fileread('file2.dat...

6 years ago | 0

| accepted

Answered
Import files based on file name
fnm = {... 'LedgeTest_muSP_0.10_muRP_0.10.1.data.0',... 'LedgeTest_muSP_0.10_muRP_0.10.1.data.1',... 'LedgeTest_muSP_0.10_muR...

6 years ago | 0

| accepted

Answered
set all the values of row i to zero in two dimensional array.
Given a numeric matrix Nbr: Nbr(i,:) = 0 https://www.mathworks.com/help/matlab/math/array-indexing.html https://www.mathworks...

6 years ago | 0

| accepted

Answered
import multiple excel file
D = 'absolute or relative path to the folder where the files are saved'; Sc = dir(fullfile(D,'*.csv')); Sx = dir(fullfile(D,'*...

6 years ago | 0

Answered
How to (nicely) copy a structure array field into another
Matlabcalifragilisticexpialidocious: [S.name] = deal(data.name) https://www.mathworks.com/help/matlab/ref/deal.html

6 years ago | 1

| accepted

Answered
Approximating Pi by Using Ramanujan's Formula
>> k = 5; >> V = 0:k; >> N = factorial(4.*V).*(1103+26390.*V); >> D = (factorial(V).^4).*(396.^(4.*V)); >> (2*sqrt(2)/9801)*...

6 years ago | 1

| accepted

Answered
How do I write a command to input "your name" and then display your name on the command window?
Note that Walter Roberson's answer is incorrect and will throw an error. It should actually be: str = input('your name','s'); ...

6 years ago | 0

Answered
sscanf with cell array of strings
Probably the most efficient solution: >> C = {'2_5_7';'10_2_6';'4_3_7';'3_10_11';'3_16_11'}; >> X = [2,4]; >> M = sscanf(spri...

6 years ago | 0

| accepted

Answered
Does this variable exist
For structures: https://www.mathworks.com/help/matlab/ref/isfield.html For tables: https://www.mathworks.com/matlabcentral/an...

6 years ago | 0

| accepted

Answered
Polar to cartesian conversion problem
"but something goes wrong because if I convert it back (from cartesian to polar) I don't get the same results" Nothing goes wro...

6 years ago | 0

| accepted

Answered
Choosing specific columns and rows
Y = S.data(...); ^^ you need to access the field of structure S https://www.mathworks.com/help/matlab/matlab_prog/access-d...

6 years ago | 0

| accepted

Answered
How can I add zeros between elements of a matrix?
>> A = [1,2,3]; Method one: indexing: >> B = zeros(size(A).*[1,2]); >> B(1:2:end) = A B = 1 0 2 0 3 0 Method ...

6 years ago | 2

Answered
Find consecutive number of specific length in a vector
>> n = 5; >> x = [10,10,10,10,11,11,11,11,11,12,12,13,13,13,13,13]; >> f = find([true,diff(x)~=0,true]); >> d = diff(f)==n; ...

6 years ago | 1

| accepted

Answered
How to adapt a script to go through different subfolders?
Both of your loops suffer the same problem: you delete only the last file. This is because after the loop you use the loop itera...

6 years ago | 0

| accepted

Answered
Plot marker on points not specified within the vector
You might think this is easy, but there is no simple, general solution for an arbitrary (i.e. non-monotonic) function and an arb...

6 years ago | 0

| accepted

Answered
markers not getting joined in plot
You are plotting scalar values in a loop, which will show individual markers unconnected by a line. If you want to have markers...

6 years ago | 0

| accepted

Answered
Replacing the minimum of a vector
" It seems random, but that doesn't make sense." It is not random, and it makes perfect sense. According to the min documentat...

6 years ago | 0

| accepted

Answered
Split cell arrays into seperate matrix; Indexing problem with cell array
"Maybe you could help me with a neat solution" The neat solution is to use MATLAB's arrays effectively. For example, something ...

6 years ago | 1

| accepted

Answered
Reduce string length after check, with one line
x = x(1:min(5,end))

6 years ago | 0

| accepted

Answered
Fast method for findings which rows of a matrix are contained in another
>> A = [1,2,3,4;5,6,7,8;9,10,11,12] A = 1 2 3 4 5 6 7 8 9 10 11 12 >> B = [...

6 years ago | 1

| accepted

Load more