getting error using code for continuing input on new line

1 Ansicht (letzte 30 Tage)
Muazma Ali
Muazma Ali am 28 Aug. 2019
Bearbeitet: Geoff Hayes am 29 Aug. 2019
Hi
I am getting error when I run this part of my code:
function det_beste_saltet=find_best_salt_available()
% antar at maksimum to kombinasjoner på salter er tilgjengelig,for å spare
% tid men programmet skal senere utvikles til å gjelde tre kombinasjoner av salter som er tilgjengelige.
% I industrien brukes flere salter samtidig men her har jeg valgt å bruke
% et av saltene som er tilgjengelig grunnet mangel på formler, i
% virkeligheten brukes flere salter med flere andre formål enn å redusere
% slammets aktivitet, for eksempel en kombinasjoner av salter der man også
% ser på hvilket salter (ioner) som har høy hydratisert radius og dermed
% stor membraneffektivitet, som også kan gi økt reduksjon i poretrykket som
% resultat i likhet med lav verdi på slammets aktivitet , hvilket dette
% delprogrammet baserer seg på, men hvis valget står mellom to salter med
% verdier på slammets aktivtitet (akt på saltløsningen) som ikke avvikser
% mye fra hverandre, er formatsalter å foretrekke pga andre fordeler ved
% dem itillegg til lav vann aktivitet som kan føre til mindre poretrykkøkning i
% skifer over tid grunnet økt viskøsitet for eks.
% det_beste_saltet= blanks(1);
antall_salter_tilgjengelige=input('Enter the number of salts available. ');
if antall_salter_tilgjengelige==2
combinations_available=input(['Enter the number associated with the combination of salts available. Enter 0 if none of the combinations are available.,'...
'\n1: Only Cloride-salts are available,',...
'\n2: ZnBr is available with one Cloride salt,',...
'\n3: NH4Cl2 is availble with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,'...
'\n4: ZnBr is available with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,',...
'\n5: CH3CO2K is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,',...
'\n6: CH3CO2K is available with one of these salts: 1) ZnSO4, 2) HCOONa, 3)HCOOK,',...
'\n7: ZnSO4 is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2 4) NaCl, 5) KCl,',...
'\n8: ZnSO4 is available with one of these formates, 1)HCOONa, 2)HCOOK,',...
'\n9: HCOONa is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,',...
'\n10: HCOOK is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,',...
'\n11: HCOONa and HCOOK. '])
The error says: Warning: File: find_best_salt_available.m Line: 25 Column: 37 .(the line 25 is combinations_available=input(['Enter the number associated with the combination of salts available. Enter 0 if none of the combinations are available.,'... )
The expression on this line will generate an error when executed. The error will be: Error using vertcat
Dimensions of matrices being concatenated are not consistent.

Antworten (1)

Geoff Hayes
Geoff Hayes am 28 Aug. 2019
Bearbeitet: Geoff Hayes am 28 Aug. 2019
Muazma - you are trying to vertically concatenate strings that are of different lengths and so the error message makes sense. Try removing the commas in front of the ... so that the strings are horizontally concatenated (the \n in the strings should handle the new line). i.e.
combinations_available=input(['Enter the number associated with the combination of salts available. Enter 0 if none of the combinations are available.,'...
'\n1: Only Cloride-salts are available,'...
'\n2: ZnBr is available with one Cloride salt,'...
'\n3: NH4Cl2 is availble with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,'...
'\n4: ZnBr is available with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,'...
'\n5: CH3CO2K is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n6: CH3CO2K is available with one of these salts: 1) ZnSO4, 2) HCOONa, 3)HCOOK,'...
'\n7: ZnSO4 is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2 4) NaCl, 5) KCl,'...
'\n8: ZnSO4 is available with one of these formates, 1)HCOONa, 2)HCOOK,'...
'\n9: HCOONa is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n10: HCOOK is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n11: HCOONa and HCOOK. '])
An alternative approach might be to build the input message string with sprintf.
  2 Kommentare
Muazma Ali
Muazma Ali am 29 Aug. 2019
I am getting the same error though I have removed the ', ' in fron of the ... Tried just to run these input sentences without the rest of the programme but again the error was connected to the input named as combination_available, the error that I get:
' Error using vertcat
Dimensions of matrices being concatenated are not consistent.'
The code that was run:
combinations_available=input(['Enter the number associated with the combination of salts available. Enter 0 if none of the combinations are available.,'...
'\n1: Only Cloride-salts are available'...
'\n2: ZnBr is available with one Cloride salt'...
'\n3: NH4Cl2 is availble with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,'...
'\n4: ZnBr is available with: 1) CH3CO2K, 2) ZnSO4, 3) HCOONa, 4)HCOOK,'...
'\n5: CH3CO2K is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n6: CH3CO2K is available with one of these salts: 1) ZnSO4, 2) HCOONa, 3)HCOOK,'...
'\n7: ZnSO4 is available with one of these chlorides: 1) NH4Cl2, 2) MgCl2, 3) CaCl2 4) NaCl, 5) KCl,'...
'\n8: ZnSO4 is available with one of these formates, 1)HCOONa, 2)HCOOK,'...
'\n9: HCOONa is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n10: HCOOK is available with one of these chlorides, 1) NH4Cl2, 2) MgCl2, 3) CaCl2, 4) NaCl, 5) KCl,'...
'\n11: HCOONa and HCOOK. '])
Geoff Hayes
Geoff Hayes am 29 Aug. 2019
Bearbeitet: Geoff Hayes am 29 Aug. 2019
Muazma - the code that I put in my answer works...so try using that. I suspect that your code fails because of the empty lines.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Eigenvalues & Eigenvectors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by