How to input a data variable with 2 different values?

4 次查看(过去 30 天)
I'm trying to make my variable S (section area of a member of a structure) to take on different values as I change the member of a structure. The program consists of determining and characterizing an engineering structure and to complete my project I used the "questdlg" in the data program to ask if all the bars had the same "S". When I answer yes I just input my single value and everything works fine but when I answer no and input the areas in each bar manually the program only assumes one value.
message = sprintf('As barras têm todas a mesma área de secção trasnversal?');
button = questdlg(message, 'Dados', 'Sim', 'Não', 'Sim');
drawnow;
if strcmpi(button, 'Sim')
fprintf('\n');
disp('As barras têm todas a mesma área da secção');
fprintf('\n');
S=input ('Área da secção transversal das barras = ');
elseif strcmpi(button, 'Não')
for j=1:NB
disp('Barra nº:')
fprintf('\n');
disp(j);
fprintf('\n');
S=input ('Área da secção transversal das barras = ');
end
end
On the "run" program I use:
S=fread(fid,1,'float32');
This means it is only reading one value but I wanted it to read at least two values. For example, one structure with 4 bars and 2 of those have S=10cm^2 and the other two have S=5cm^2. Can you help?
  2 个评论
Image Analyst
Image Analyst 2022-8-16
What is the name of the structure variable? What are the fieldnames of the structure?
What is fid? Are you opening a file on disk for reading from?
João Ventura
João Ventura 2022-8-16
Hello! Basically i have 2 programms, the first one is where i inpute the variables and second one is where he reads and do the calculations.
I did some changes and it worked he is already assuming two different values for "S", the problem now is that I had some exercices/data saved and they have same "S" for all struture and now they are not working with the settings i changed. My solution was to had simmilar lines to programm and comment the "changes".
This is the data programm, where i input the variables:
message = sprintf('The bars have the same "S"?');
button = questdlg(message, 'Data', 'Yes', 'No', 'Yes');
drawnow;
if strcmpi(button, 'Yes')
fprintf('\n');
disp('The bars have the same "S".');
fprintf('\n');
S=input ('"S" assumes value = ');
elseif strcmpi(button, 'No')
for j=1:NB (**NB=number of bars I input few lines earlier**)
disp('Bar nº:')
fprintf('\n');
disp(j);
fprintf('\n');
S(j)=input ('"S" assumes value = ');
end
end
Now, this is on the execution program:
NB=fread(fid,1,'int16');
NN=fread(fid,1,'int16');
NDF=fread(fid,1,'int16');
E=fread(fid,1,'float32');
S=fread(fid,1,'float32'); (*** I uncomment this line when there is 1 "S"***)
%S=fread(fid,NB,'float32'); (*** I uncomment this line when there is 2+ "S"***)
X=fread(fid,NN,'float32');
Y=fread(fid,NN,'float32');
ExtE=fread(fid,NB,'int16');
ExtD=fread(fid,NB,'int16');
NDD=fread(fid,NDF,'int16');
VDD=fread(fid,NDF,'float32');
CH=fread(fid,NN,'float32');
CV=fread(fid,NN,'float32');
for j=1:NB
DX=X(ExtD(j))-X(ExtE(j));
DY=Y(ExtD(j))-Y(ExtE(j));
a=DY/DX;
alfa=atand(a);
h=DX/DY;
beta=atand(h);
l=sqrt(DX^2+DY^2);
%kl= [E*(S(j))/l 0 -E*(S(j))/l 0; 0 0 0 0; -E*(S(j))/l 0 E*(S(j))/l 0; 0 0 0 0]; (***again here***)
kl= [E*S/l 0 -E*S/l 0; 0 0 0 0; -E*S/l 0 E*S/l 0; 0 0 0 0]; (***again here***)
My question is there is another solution for this? Instead of comment/uncomment the lines?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-8-16
S(j) = input ('Área da secção transversal das barras = ');
  1 个评论
João Ventura
João Ventura 2022-8-16
Hello! It really helped but now the programm settings only work for 2+ "S". If i use one exercise with just 1 value for "S" he will show up an error:
"Array indices must be positive integers or logical values"
My solution was to add lines that worked fine for exercises with just 1 "S" and then "play" with the commenting and uncommenting. Is there any other solution for this? The example of my programm is in the comment early to the other user, if you don't mind can you take a look, please?
Thank you for the help.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Functions 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by