Answered
Convert rows an columns of 4D matrix into 2d matrix with rows and columns as index Ai_j
You will get an error because plot accepts matrices only (i.e. 3rd and higher dimensions must be scalar), but apparently you are...

6 years ago | 0

| accepted

Answered
Matrix dimensions must agree error
Wrap each input with str2double, e.g.: Temp_Coke = str2double(input('What is the current temperature of the Coke (deg F)? ', 's...

6 years ago | 0

| accepted

Answered
Generating matrix from another array
>> E3 = [2,1,0,4,25,19,2,2,3,3,4,5,6,7,8,7,19]; >> X = diag(cumsum(bsxfun(@eq,E3,E3(:)),1)); >> C = arrayfun(@(n)E3(X==n),1:ma...

6 years ago | 0

| accepted

Answered
recursive function to calculate Max number.
Urmish Haribhakti's general approach is quite good, with a few small changes it will work correctly: function x = recmax(v) if...

6 years ago | 5

| accepted

Answered
Field of a structure
M = mean(T.HV3) and then use writematrix.

6 years ago | 0

| accepted

Answered
Invalid file identifier. Use fopen to generate a valid file identifier.
You need to use the directory information in two locations: both with dir and with fopen, e.g.: vec_dir = 'Z:\Flotation_chamber...

6 years ago | 0

Answered
storing value in a variable
It looks like you are trying to declare a variable type. MATLAB does not have variable type declarations. This is what your MAT...

6 years ago | 3

| accepted

Answered
m-file to find elements (text) in an alloy
>> str = 'Al0.1Co0.25Cu14AaBb'; >> [mat,spl] = regexp(str,'[A-Z][a-z]*','match','split'); >> vec = str2double(spl(2:end)); >>...

6 years ago | 0

| accepted

Answered
How to avoid the two loops with a less memory consumption.
A = exp(x(:).'-x(:) + y(:).'-y(:)); This requires MATLAB version >=R2016b. For earlier versions replace the subtraction with bs...

6 years ago | 0

| accepted

Answered
Writing a Script..
D = 'absolute or relative path to the folder file where the files are saved'; S = dir(fullfile(D,'Case*.mat')); N = numel(S); ...

6 years ago | 0

| accepted

Answered
How do I get 2 strings to print in between each other?
If they have exactly the same number of characters: Method one: reshape: >> s1 = 'HELLO MATLAB'; >> s2 = 'greetings us'; >> ...

6 years ago | 0

| accepted

Answered
How do I use fprintf to print a matrix of MxM size where User chooses M
>> N = 4; >> M = randi([0,1],N,N); >> F = [repmat(' %d',1,N),'\n']; >> fprintf(F,M.') 1 0 1 1 1 1 1 1 0 1 1 0 1 0 1 1...

6 years ago | 0

| accepted

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

Load more