Skip to main content

All Questions

Tagged with
0 votes
1 answer
438 views

How can I add line breaks in between code outputs in a MatLab live script?

I have this code in a live script cell: u = symunit; syms V_GS V_t_value = 0.4*u.V; K_n_W_L_value = 2*u.mA/u.V^2; %get V_GS i_d_equation_saturation = 0.5*K_n_W_L_value*(V_GS - V_t_value)^2; assume(...
Mikayla Eckel Cifrese's user avatar
2 votes
1 answer
110 views

matlab fprintf with formatspec based on value

Say I want to print two numbers 1.755 1.234e-5 For the former, I would write fprintf('%.3f', 1.755) and for the latter fprintf('%.3e', 1.234e-5) Clearly, the first formatspec does not make sense ...
SolidMechanicsFan's user avatar
0 votes
1 answer
87 views

fprintf Command in Gauss-Seidel MATLAB Code

I have the following MATLAB code for solving a system of equation using the Gauss-Seidel Method. I'm wondering what the percentages mean in the fprintf command? `k = 1; x1 = 0; x2 = 0; x3 = 0; disp(‘ ...
Chesso's user avatar
  • 167
1 vote
1 answer
69 views

write two matlab vectors in a file and insert backslash between the vectors

Given a=[1 2 3]; b=[4 5 6]; Output in file should look like: 1 2 3 / 4 5 6 Is there a way to achieve this in one single fprintf() call? I have a solution where there is no backslash between a and b ...
SolidMechanicsFan's user avatar
1 vote
1 answer
35 views

Iterating numbers within a string (Matlab)

In Matlab I am trying to achieve the following: I need to provide an end date, which I would like to iterate forward by quarter in the format: '1970q1' For this I have made a loop. for yy=1970:1971 ...
Suttungr's user avatar
0 votes
0 answers
195 views

Why doesn't zero padding with integers work in Matlab formatSpec?

I am trying to pad a number with zeros as follows. Desired: 7 -> '07' 8 -> '08' (In case it matters, the input is intended as a character vector to be converted by num2str. But for the examples ...
Argyll's user avatar
  • 9,899
0 votes
1 answer
165 views

Contatenating strings using sprintf

I wonder why the following code does not work? function out = test(str1, str2) aux = sprintf(str1, str2); end Somehow MATLAB does not like how I supply the argument str1, which is entered by the ...
Billy's user avatar
  • 13
0 votes
2 answers
84 views

The \n doesn't work in Matlab when i write the datestring in file

I have a problem with \n when I am trying to write a datestring and number values in txt file pattern = [ ... 'Date %s - First %d \n', ... 'Date %s - Second %d \n' ... '%d, \n', ... '*...
Count Zero's user avatar
0 votes
1 answer
601 views

Using equation stored in variable Matlab

I want to use a equation which is stored in variable using inline Function but I am getting an error of 'Check for incorrect argument data type or missing argument in call to function 'coeffs'. '. ...
shakaib naqvi's user avatar
4 votes
1 answer
347 views

Merge strings and table to one text file using fprintf - Matlab

How can I save the information generate in the script below which include strings and table in the following format to a text file? Format: M=5 1 21 2 22 3 23 4 24 5 25 5points Script: clc; clear all;...
alirazi's user avatar
  • 161
2 votes
1 answer
47 views

Create table from structure in matlab - alignment

I have a structure with scalar fields, say mom, and I would like to display the values of the structure on the screen in aligned columns, possibly with some header. Here is a minimum working example: ...
Alessandro's user avatar
0 votes
0 answers
217 views

using fprintf to print a float with a user specified precision

I have a script in matlab that takes inputs from the user, computes some value and prints it on the screen. The script is quite complex and I would like to be able to give the user the option to ...
Samuel Snerden's user avatar
1 vote
0 answers
99 views

How to change display the equation into f(x)=0.0667*x in MATLAB command window?

I have a MATLAB code clear all; clc; syms x; f=2/30*x; f=vpa(f,3); fprintf('f(x)=%s\n',char(f)); The result is f(x)=.667e-1*x Now I want to display in command window: f(x)=0.0667*x Anyone can help ...
Ongky Denny Wijaya's user avatar
3 votes
0 answers
313 views

Print to MATLAB command window from mex file and another thread

I modified a sample program to demonstrate the issue: It prints a string each second. The problem is that the messages appear in the command window after MATLAB returns to idle state (all at once). If ...
MiB_Coder's user avatar
  • 907
0 votes
1 answer
111 views

Strange behaviour when writing RTF file

I have a strange behaviour in Matlab dealing with RTF files. The rtf file is read with this instruction: cin = textread(filename, '%s', 'delimiter', '\n'); (cin) is a Nx1 cell where N is the number ...
vaiadubai's user avatar

15 30 50 per page
1
2 3 4 5
18