Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fprintf and axis problem

Subject: fprintf and axis problem

From: Konst

Date: 18 Oct, 2010 15:34:04

Message: 1 of 8

I am currently analyzing an electric signal an I have two problems
1)I use fprintf to save some data in a txt form
fprintf('numb=%f\t',numb);
   fprintf('\t\n');
   fprintf('distance=%f\t',d);
 and I take
numb=1 numb=2 numb=3
distance=0.34 distance=3.9 distance=8.22

but I need to be in this form:
numb distance
1 0,34
2 3.9
3 8.22

\v in the fprintf command doesn't seem to work


2)I use ginput to select two points on the curve and then draw a rectangle with width the distance of these to points and height 1.But when I do these the axis 'transforms' into a line and I can't seen neither the original curve nor the rectangle(hold on is on).I tried axis tight, axis manual but they dont work

So please if anyone has a solution for these two problems I would really be very gratefull...

Subject: fprintf and axis problem

From: Konst

Date: 18 Oct, 2010 16:16:03

Message: 2 of 8

Sorry I mean that the whole graph transforms into a thin line, not the axis..Anyone?

Subject: fprintf and axis problem

From: someone

Date: 18 Oct, 2010 18:06:03

Message: 3 of 8

"Konst " <konstance1@hotmail.com> wrote in message <i9hpdc$nu7$1@fred.mathworks.com>...
> I am currently analyzing an electric signal an I have two problems
> 1)I use fprintf to save some data in a txt form
> fprintf('numb=%f\t',numb);
> fprintf('\t\n');
> fprintf('distance=%f\t',d);
> and I take
> numb=1 numb=2 numb=3
> distance=0.34 distance=3.9 distance=8.22
>
> but I need to be in this form:
> numb distance
> 1 0,34
> 2 3.9
> 3 8.22

doc fprintf

% Look at the first example. It does EXACTLY what you want.
>
> \v in the fprintf command doesn't seem to work

% I don't see a "/v" option, so I'm not surprised it doesn't work.
>
>
> 2)I use ginput to select two points on the curve and then draw a rectangle with width the distance of these to points and height 1.But when I do these the axis 'transforms' into a line and I can't seen neither the original curve nor the rectangle(hold on is on).I tried axis tight, axis manual but they dont work

% How do you you know it doesn't work?
% Do you get any error messages?
% Can you provide a short snipplet of the relevant code you are using?
>
> So please if anyone has a solution for these two problems I would really be very gratefull...

Subject: fprintf and axis problem

From: Konst

Date: 18 Oct, 2010 18:36:04

Message: 4 of 8

I need one column for numb and one for the distances but these commands put it in rows.This is my original algorithm.I tried /v and axis tight/manual for the second problem 'at home' so that's the reason you don't see it.All it does is to stuff it all together with no spaces between them
% X=my electric signal as a vector.for a simple vector it works fine but not for complicated graphs(imagine a cardiogram)
pause %for zoom in a certain area
 [x] = ginput(2);
disp (x(2))
disp (x(1))
d(i)=x(2)-x(1)
axis manual
rectangle('Position',[x(1),0,x(2)-x(1),1],'Curvature',[0,0],'EdgeColor',[1,0,0])
daspect ([1,1,1])
and all these in an for-loop which breaks after some times

Thank you for your time though..

Subject: fprintf and axis problem

From: someone

Date: 18 Oct, 2010 19:09:04

Message: 5 of 8

"Konst " <konstance1@hotmail.com> wrote in message <i9i42k$sg9$1@fred.mathworks.com>...
> I need one column for numb and one for the distances but these commands put it in rows.

Did you type "doc fprintf" at the command line prompt and look at the first example as I suggested. The example shows how to print two columns of data. If this does not answer your first problem, why not?

This is my original algorithm.I tried /v and axis tight/manual for the second problem 'at home' so that's the reason you don't see it.All it does is to stuff it all together with no spaces between them
> % X=my electric signal as a vector.for a simple vector it works fine but not for complicated graphs(imagine a cardiogram)
> pause %for zoom in a certain area
> [x] = ginput(2);
> disp (x(2))
> disp (x(1))
> d(i)=x(2)-x(1)
> axis manual
> rectangle('Position',[x(1),0,x(2)-x(1),1],'Curvature',[0,0],'EdgeColor',[1,0,0])
> daspect ([1,1,1])
> and all these in an for-loop which breaks after some times
>
> Thank you for your time though..

Try this and see what happens:

[x,y] = ginput(2);
disp (x(2))
disp (x(1))
d(i)=x(2)-x(1)
% axis manual
rectangle('Position',[x(1),y(1),x(2)-x(1),y(2)-y(1)],'Curvature',[0,0],'EdgeColor',[1,0,0])

Subject: fprintf and axis problem

From: Konst

Date: 18 Oct, 2010 19:36:04

Message: 6 of 8

ok but way y(2)-y(1) in the rectangle?I want a specific height.Anyway I tried it but it displays error when the y2 is lower than the y1 so it doesn't works exactly..
Thanks anyways

Subject: fprintf and axis problem

From: dpb

Date: 18 Oct, 2010 19:56:10

Message: 7 of 8

Konst wrote:
> ok but way y(2)-y(1) in the rectangle?I want a specific height.Anyway I
> tried it but it displays error when the y2 is lower than the y1 so it
> doesn't works exactly..
...

Well, you didn't say _what_ specific height you wanted; someone used his
crystal ball to presume that since you used x(2)-x(1) that by parallel
y(2)-y(1) would be a good shot for the height.

If y(2)-y(1)<0 then use abs() for the height.

Altho you clipped so couldn't see it, I see you use "1" as a height
initially -- unless the magnitude of y(2)-y(1) is numerically similar in
magnitude, that will either be very tall or very short...

--

Subject: fprintf and axis problem

From: Konst

Date: 19 Oct, 2010 14:52:03

Message: 8 of 8

I solvethe axis problem eventually by deleting the daspect command..Anyone for the first?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us