Answered
Aligning columns with fprintf
You can use '%g' to print values with trailing zeros removed: X = 0.5:0.5:2.5; Y = 500:250:1500; M = [425,1441,2651,3665,4091...

6 years ago | 0

| accepted

Answered
Open multiple files from the same folder with fopen and textscan
Following the examples in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.ht...

6 years ago | 0

Answered
A point charge of Q = 5 nC is located at (2,2,8). how to find the distance of the electric fields generated by the charge over the range of 0 < x < 4 m, 0 < y < 4 m, and 0 < z < 4 m due to the point charge?
>> [xA,yA,zA] = ndgrid(x,y,z); >> rA = sqrt( (xA-2).^2 + (yA-2).^2 + (zA-8).^2 ); Of course rA will actually have size numel(x...

6 years ago | 0

| accepted

Answered
Cell array summation when arrays are different sizes
Without any padding with extra zeros/NaN/etc. Generate some indices to use accumarray to sum only the required elements: >> in...

6 years ago | 1

| accepted

Answered
How to remove first consonant/consonant cluster and add it to the end?
>> a = {'desk', 'hello', 'cup', 'switch', 'smith', 'flowers', 'angry', 'decorations'}; >> regexprep(a,'(^[^aeiou]+)(.+)','$2$1'...

6 years ago | 0

Answered
Find last row of csv contents using fopen, fgetl?? Or, another way?
Use feof like this: while ~feof(fid); tline = fgetl(fid); ... end

6 years ago | 0

| accepted

Answered
Best way to pass large amounts of variables between functions
"What would be the best way to pass variables between functions?" There is no simple answer because it depends on the nature of...

6 years ago | 1

| accepted

Answered
Defining table reference using list contents
Dragging-and-dropping into MATLAB actually makes your task harder, because it creates lots of separate variables. Drag-and-drop ...

6 years ago | 0

| accepted

Answered
How to parse a file with value pairs
This works with the attached file (which I had to create myself): T = table(); [fid,msg] = fopen('temp0.txt','rt'); assert(fi...

6 years ago | 0

| accepted

Answered
Excercises for MATLAB programmimg
"Should I assume that there is no web portal that offers questions like that" This one: https://projecteuler.net/

6 years ago | 0

Answered
Input arguments to function include colon operator. To input the colon character, use ':' instead.
The function mycon3 is not correctly defined. The fmincon documentation states that its optional nonlcon input argument should ...

6 years ago | 1

| accepted

Answered
Rearranging dates to make them suitable for datetime format
>> C = {'08/21/2020 (Aug)';'05/26/2018 (May)';'04/03/2016';'02/06/2005 (QQ)'}; >> D = datetime(regexp(C,'^.{10}','match','once'...

6 years ago | 1

| accepted

Answered
How can i open the attached text file or other formate file given in community in my own matlab
"How can i open the attached text file..." Download the file, then run either: V = dlmread('Xc.txt'); or V = readmatrix('Xc....

6 years ago | 0

| accepted

Answered
Vectorisation of a loop
X = X1+[0;cumsum(Vx(1:end-1).*diff(T))] Y = Y1+[0;cumsum(Vy(1:end-1).*diff(T))]

6 years ago | 0

| accepted

Answered
nchoosek with multiple arrays
Simply generate a matrix of indices: idx = nchoosek(1:33,3); and then for each row in that matrix perform your calculations, w...

6 years ago | 0

| accepted

Answered
How to convert matrix format
You do not give enough information about the order you want the elements to be in, but this should get you started: >> B = resh...

6 years ago | 1

| accepted

Answered
extract data from cell array based on matching numbers with location in array
Where C is your cell array of data: B = C(A) https://www.mathworks.com/help/matlab/math/array-indexing.html https://www.mathw...

6 years ago | 1

| accepted

Answered
Removing repeated numbers in a matrix
>> A = [9,9,1,1,2,2,2,2,2,0,3,3;7,7,4,4,4,5,5,6,6,6,6,6;8,8,7,7,7,8,8,8,9,9,9,5] A = 9 9 1 1 2 2 2 2 2 0 ...

6 years ago | 2

| accepted

Answered
Read Images After Sorting with natsortfiles
Do NOT redefine the natsortfiles function! Do NOT save this in a file named natsortfiles! Simply following the examples in the ...

6 years ago | 0

| accepted

Answered
Extracting length information of pattern from specific string (not fixed string)
One simple dynamic regular expression can do this quite efficiently: >> fun = @(s)sprintf('[01]{%d}',bin2dec(s)); >> rgx = '01...

6 years ago | 1

| accepted

Answered
Why does my function graph look like a net? How to improve it?
"As for each value t there should be only one value for ft." Each vector contains exactly 1681 elements, so that is true. But t...

6 years ago | 0

| accepted

Answered
How to add a new field to a struct array inside a cell array
Rather than a cell array of scalar structures (difficult to work with) you should use one structure array (easier to access): A...

6 years ago | 1

Answered
how to convert cell array of struct to matrix
Rather than creating a cell array of scalar structures, you should create one single structure array: >> S(1).time = 1:10; % I ...

6 years ago | 0

Answered
Reading and renaming a variable from .mat file in appdesigner
It will be much simpler if you load into an output variable (which itself is a scalar structure): S = load(app.FileName.Value);...

6 years ago | 0

| accepted

Answered
Pick values around an index
>> V = [0, 11, 12, 13, 14, 0, 21, 22, 23, 0, 31, 32, 33, 34, 35]; >> X = logical(conv([1,1,1,1],+(V==0))); >> Z = V(X(1:numel(...

6 years ago | 1

| accepted

Answered
How to save some values from one vector to another
"I know I have to do it in a for loop but I failed." Why do you need to use a loop? The MATLAB way is to use simple logical ind...

6 years ago | 0

| accepted

Answered
Matrix indexing- How to assign variable c to second row of A
A(2,:) = c As explained here: https://www.mathworks.com/help/matlab/getting-started-with-matlab.html

6 years ago | 0

| accepted

Answered
how to find index of string using AND operator when adding conditions
>> zz = {'2','B','A';'2','C','A';'2','V','H';'2','B','Y';'3','F','A';'3','G','A';'3','B','A';'2','G','A'} zz = '2' 'B'...

6 years ago | 0

| accepted

Answered
Why Nested For Loop Is not showing me the index values from 1 to N interval ?
MATLAB does not display infinite lines in the command window scroll buffer. By default it displays the last 5000 lines, as expla...

6 years ago | 0

| accepted

Answered
How to read .txt file which have complex numbers and how to separate real and imaginary parts of the complex numbers?
1. Remove the space characters embedded in the complex numbers: opt = {'MultipleDelimsAsOne',true,'HeaderLines',1}; str = fil...

6 years ago | 1

Load more